Skip to content

Commit 7dbc5b9

Browse files
committed
Use interval.getStringRep for ReportingAttachment's interval (#75146)
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.
1 parent b851829 commit 7dbc5b9

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
setup:
3+
- do:
4+
cluster.health:
5+
wait_for_status: yellow
6+
7+
---
8+
"Test put watch with a reporting interval":
9+
- do:
10+
watcher.put_watch:
11+
id: "my_watch_with_reporting_interval"
12+
body: >
13+
{
14+
"trigger": {
15+
"schedule" : { "cron" : "0 0 0 1 * ? 2099" }
16+
},
17+
"actions": {
18+
"email_admin": {
19+
"email": {
20+
21+
"subject": "Monitoring Report",
22+
"attachments": {
23+
"report_csv": {
24+
"reporting": {
25+
"url": "https://example.com",
26+
"retries": 10,
27+
"interval": "66s"
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
35+
- match: { _id: "my_watch_with_reporting_interval" }
36+
37+
- do:
38+
watcher.get_watch:
39+
id: "my_watch_with_reporting_interval"
40+
- match: { found : true}
41+
- match: { _id: "my_watch_with_reporting_interval" }
42+
- match: { watch.actions.email_admin.email.attachments.report_csv.reporting.interval: "66s" }

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/email/attachment/ReportingAttachment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
9292
}
9393

9494
if (interval != null) {
95-
builder.field(INTERVAL.getPreferredName(), interval);
95+
builder.field(INTERVAL.getPreferredName(), interval.getStringRep());
9696
}
9797

9898
if (inline) {

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/notification/email/attachment/ReportingAttachmentParserTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public void testSerializationWorks() throws Exception {
106106
TimeValue interval = null;
107107
boolean withInterval = randomBoolean();
108108
if (withInterval) {
109-
builder.field("interval", "1s");
110-
interval = TimeValue.timeValueSeconds(1);
109+
interval = TimeValue.parseTimeValue(randomTimeValue(1, 100, "s", "m", "h"), "interval");
110+
builder.field("interval", interval.getStringRep());
111111
}
112112

113113
boolean isInline = randomBoolean();

0 commit comments

Comments
 (0)