-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Watcher: migrate PagerDuty v1 events API to v2 API #32285
Conversation
The PagerDuty v1 API is EOL and will stop accepting new accounts shortly. This commit swaps out the watcher use of the v1 API with the new v2 API. It does not change anything about the existing watcher API. Closes elastic#32243
Pinging @elastic/es-core-infra |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like much fewer changes than expected. Testing with a v2 token needs to be done as well.
Do you think it's worth adding some tests?
} | ||
|
||
// TODO externalize this into something user editable | ||
builder.field("source", "watcher"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe have the watch id in here (if possible) to easily pinpoint the source?
|
||
if (attachPayload) { | ||
builder.startObject("custom_details"); | ||
builder.field(Fields.PAYLOAD.getPreferredName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace two lines with
builder.field(Fields.PAYLOAD.getPreferredName(), payload, params);
{ | ||
builder.field("summary", description); | ||
|
||
if (attachPayload) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure: This gets parsed properly on the other side if you leave it out (and dont have the custom_details
structure)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
custom_details is not mandatory, so it will def leave it out. Ill add a null check for payload as well in this statement
implemented the changes. Yes, ill do some manual verification once i obtain a v2 token. Also, what kind of test did you have in mind besides the 3rd party ones? Thats what i was using to verify up to now. cc @spinscale |
@elasticmachine test this please |
testing was mostly referred to proper JSON construction (check if fields are not written if certain elements are null etc). |
…t emits valid json
@@ -92,6 +92,85 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |||
return builder.endObject(); | |||
} | |||
|
|||
public static IncidentEventContext parse(XContentParser parser) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are straight copys of the Template's parse method, but without the TextTemplate mess. These will be used in the future when i finally finish removing the Templates :)
@@ -39,7 +39,8 @@ | |||
public class IncidentEvent implements ToXContentObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also fix the above links, as they probably link to the old documentation?
.build(); | ||
} | ||
|
||
public XContentBuilder buildAPIXContent(XContentBuilder builder, Params params, String serviceKey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package visibility?
@@ -93,46 +94,96 @@ public int hashCode() { | |||
return result; | |||
} | |||
|
|||
public HttpRequest createRequest(final String serviceKey, final Payload payload) throws IOException { | |||
public HttpRequest createRequest(final String serviceKey, final Payload payload, final String watchId) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packabe visibility?
*/ | ||
private void toXContentV2Contexts(XContentBuilder builder, ToXContent.Params params, | ||
IncidentEventContext[] contexts) throws IOException { | ||
// contexts can be either links or images, and the v2 api needs them separate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about making this more readable (at least to me :-)
Map<IncidentEventContext.Type, List<IncidentEventContext>> groupByType =
Arrays.stream(contexts).collect(Collectors.groupingBy(ctx -> ctx.type));
List<IncidentEventContext> linkContexts = groupByType.get(IncidentEventContext.Type.LINK);
if (linkContexts != null && linkContexts.isEmpty() == false) {
builder.startArray(Fields.LINKS.getPreferredName());
for (IncidentEventContext context : linkContexts) {
context.toXContent(builder, params);
}
builder.endArray();
}
List<IncidentEventContext> imagesContexts = groupByType.get(IncidentEventContext.Type.IMAGE);
if (imagesContexts != null && imagesContexts.isEmpty() == false) {
builder.startArray(Fields.IMAGES.getPreferredName());
for (IncidentEventContext context : imagesContexts) {
context.toXContent(builder, params);
}
builder.endArray();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dang i like those streams.. I still am a streaming noob. ty.
|
||
String currentFieldName = null; | ||
XContentParser.Token token; | ||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a lot of parsing code, can you use the ObjectPath
class instead. Going through this while loop in a test is pretty tedious to understand what's going on.
ObjectPath objectPath = ObjectPath.createFromXContent(jsonBuilder.contentType().xContent(), BytesReference.bytes(jsonBuilder));
actualServiceKey = objectPath.evaluate(IncidentEvent.Fields.ROUTING_KEY.getPreferredName());
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this is way nicer. tyvm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some more comments regarding readability, but I think we're almost here.
|
||
List<IncidentEventContext> actualLinks = new ArrayList<>(); | ||
List<Map<String, String>> linkMap = (List<Map<String, String>>) objectPath.evaluate(IncidentEvent.Fields.LINKS.getPreferredName()); | ||
if (linkMap != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(linkMap, is(notNullValue))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the map is not always non-null, then check this implicitely by checking another boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be null if the links are not present. They are randomly set to null in the setup code. So this can totally come back as null, which in that case it will still evaluate the images/links empty List's against the setup's empty Lists, ensuring they are the same.
|
||
List<IncidentEventContext> actualImages = new ArrayList<>(); | ||
List<Map<String, String>> imgMap = (List<Map<String, String>>) objectPath.evaluate(IncidentEvent.Fields.IMAGES.getPreferredName()); | ||
if (imgMap != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(imgMap, is(notNullValue))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left minor comments to improve the test, but LGTM otherwise
Removing the "blocker" status due to #32243 (comment). |
…e-types * elastic/master: (199 commits) Watcher: Remove unused hipchat render method (elastic#32211) Watcher: Remove extraneous auth classes (elastic#32300) Watcher: migrate PagerDuty v1 events API to v2 API (elastic#32285) [TEST] Select free port for Minio (elastic#32837) MINOR: Remove `IndexTemplateFilter` (elastic#32841) Core: Add java time version of rounding classes (elastic#32641) Aggregations/HL Rest client fix: missing scores (elastic#32774) HLRC: Add Delete License API (elastic#32586) INGEST: Create Index Before Pipeline Execute (elastic#32786) Fix NOOP bulk updates (elastic#32819) Remove client connections from TcpTransport (elastic#31886) Increase logging testRetentionPolicyChangeDuringRecovery AwaitsFix case-functions.sql-spec Mute security-cli tests in FIPS JVM (elastic#32812) SCRIPTING: Support BucketAggScript return null (elastic#32811) Unmute WildFly tests in FIPS JVM (elastic#32814) [TEST] Force a stop to save rollup state before continuing (elastic#32787) [test] disable packaging tests for suse boxes Mute IndicesRequestIT#testBulk [ML][DOCS] Refer to rules feature as custom rules (elastic#32785) ...
…listeners * elastic/master: Watcher: Remove unused hipchat render method (elastic#32211) Watcher: Remove extraneous auth classes (elastic#32300) Watcher: migrate PagerDuty v1 events API to v2 API (elastic#32285) [TEST] Select free port for Minio (elastic#32837) MINOR: Remove `IndexTemplateFilter` (elastic#32841) Core: Add java time version of rounding classes (elastic#32641) Aggregations/HL Rest client fix: missing scores (elastic#32774) HLRC: Add Delete License API (elastic#32586) INGEST: Create Index Before Pipeline Execute (elastic#32786) Fix NOOP bulk updates (elastic#32819) Remove client connections from TcpTransport (elastic#31886) Increase logging testRetentionPolicyChangeDuringRecovery AwaitsFix case-functions.sql-spec Mute security-cli tests in FIPS JVM (elastic#32812) SCRIPTING: Support BucketAggScript return null (elastic#32811) Unmute WildFly tests in FIPS JVM (elastic#32814) [TEST] Force a stop to save rollup state before continuing (elastic#32787) [test] disable packaging tests for suse boxes Mute IndicesRequestIT#testBulk [ML][DOCS] Refer to rules feature as custom rules (elastic#32785)
* elastic/master: Revert "cluster formation DSL - Gradle integration - part 2 (#32028)" (#32876) cluster formation DSL - Gradle integration - part 2 (#32028) Introduce global checkpoint listeners (#32696) Move connection profile into connection manager (#32858) [ML] Temporarily disabling rolling-upgrade tests Use generic AcknowledgedResponse instead of extended classes (#32859) [ML] Removing old per-partition normalization code (#32816) Use JDK 10 for 6.4 BWC builds (#32866) Removed flaky test. Looks like randomisation makes these assertions unreliable. [test] mute IndexShardTests.testDocStats Introduce the dissect library (#32297) Security: remove password hash bootstrap check (#32440) Move validation to server for put user requests (#32471) [ML] Add high level REST client docs for ML put job endpoint (#32843) Test: Fix forbidden uses in test framework (#32824) Painless: Change fqn_only to no_import (#32817) [test] mute testSearchWithSignificantTermsAgg Watcher: Remove unused hipchat render method (#32211) Watcher: Remove extraneous auth classes (#32300) Watcher: migrate PagerDuty v1 events API to v2 API (#32285)
The PagerDuty v1 API is EOL and will stop accepting new accounts shortly. This commit swaps out the watcher use of the v1 API with the new v2 API. It does not change anything about the existing watcher API. Closes #32243
The PagerDuty v1 API is EOL and will stop accepting new accounts
shortly. This commit swaps out the watcher use of the v1 API with the
new v2 API. It does not change anything about the existing watcher
API.
Closes #32243