Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement timeseries index model to command-manager plugin #153

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public Command(
this.status = Status.PENDING;
}

/**
* Retrieves the timeout value for this command.
*
* @return the timeout value in milliseconds.
*/
public Integer getTimeout() {
return this.timeout;
}

/**
* Parses the request's payload into the Command model.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

/** Command's target fields. */
public class Document implements ToXContentObject {
public static final String TIMESTAMP = "@timestamp";
public static final String DELIVERY_TIMESTAMP = "delivery_timestamp";
private final Agent agent;
private final Command command;
private final String id;
private final long timestamp;
private final long deliveryTimestamp;

/**
* Default constructor
Expand All @@ -32,6 +36,20 @@ public Document(Agent agent, Command command) {
this.agent = agent;
this.command = command;
this.id = UUIDs.base64UUID();
this.timestamp = System.currentTimeMillis();
this.deliveryTimestamp = calculateDeliveryTimestamp(this.timestamp, command.getTimeout());
}

/**
* Calculates the delivery timestamp by adding a specified timeout to the given timestamp.
*
* @param timestamp the initial timestamp in milliseconds.
* @param timeout the time in seconds to be added to the timestamp.
* @return a new timestamp representing the delivery time.
*/
private long calculateDeliveryTimestamp(long timestamp, int timeout) {
long timeoutInMillis = timeout * 1000L;
return timestamp + timeoutInMillis;
}

/**
Expand Down Expand Up @@ -68,11 +86,22 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.startObject();
this.agent.toXContent(builder, ToXContentObject.EMPTY_PARAMS);
this.command.toXContent(builder, ToXContentObject.EMPTY_PARAMS);
builder.field(TIMESTAMP, this.timestamp);
builder.field(DELIVERY_TIMESTAMP, this.deliveryTimestamp);
return builder.endObject();
}

@Override
public String toString() {
return "Document{" + "agent=" + agent + ", command=" + command + '}';
return "Document{"
+ "@timestamp="
+ timestamp
+ ", delivery_timestamp="
+ deliveryTimestamp
+ ", agent="
+ agent
+ ", command="
+ command
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"date_detection": false,
"dynamic": "strict",
"properties": {
"@timestamp": {
"type": "date"
},
"agent": {
"properties": {
"groups": {
Expand Down Expand Up @@ -83,6 +86,9 @@
"type": "keyword"
}
}
},
"delivery_timestamp": {
"type": "date"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"date_detection": false,
"dynamic": "strict",
"properties": {
"@timestamp": {
"type": "date"
},
"agent": {
"properties": {
"groups": {
Expand Down Expand Up @@ -83,6 +86,9 @@
"type": "keyword"
}
}
},
"delivery_timestamp": {
"type": "date"
}
}
},
Expand Down