Skip to content

Commit

Permalink
Use interval.getStringRep for ReportingAttachment's interval (#75146)
Browse files Browse the repository at this point in the history
Using getStringRep here rather than (implicitly) toString so that the
interval is serialized exactly as it was provided, rather than
converting to some other human readable form.
  • Loading branch information
joegallo committed Jul 8, 2021
1 parent 9e4ea9a commit daa33c8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
setup:
- do:
cluster.health:
wait_for_status: yellow

---
"Test put watch with a reporting interval":
- do:
watcher.put_watch:
id: "my_watch_with_reporting_interval"
body: >
{
"trigger": {
"schedule" : { "cron" : "0 0 0 1 * ? 2099" }
},
"actions": {
"email_admin": {
"email": {
"to": "example@example.com",
"subject": "Monitoring Report",
"attachments": {
"report_csv": {
"reporting": {
"url": "https://example.com",
"retries": 10,
"interval": "66s"
}
}
}
}
}
}
}
- match: { _id: "my_watch_with_reporting_interval" }

- do:
watcher.get_watch:
id: "my_watch_with_reporting_interval"
- match: { found : true}
- match: { _id: "my_watch_with_reporting_interval" }
- match: { watch.actions.email_admin.email.attachments.report_csv.reporting.interval: "66s" }
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

if (interval != null) {
builder.field(INTERVAL.getPreferredName(), interval);
builder.field(INTERVAL.getPreferredName(), interval.getStringRep());
}

if (inline) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public void testSerializationWorks() throws Exception {
TimeValue interval = null;
boolean withInterval = randomBoolean();
if (withInterval) {
builder.field("interval", "1s");
interval = TimeValue.timeValueSeconds(1);
interval = TimeValue.parseTimeValue(randomTimeValue(1, 100, "s", "m", "h"), "interval");
builder.field("interval", interval.getStringRep());
}

boolean isInline = randomBoolean();
Expand Down

0 comments on commit daa33c8

Please sign in to comment.