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

Watcher: migrate PagerDuty v1 events API to v2 API #32285

Merged
merged 18 commits into from
Aug 14, 2018

Conversation

hub-cap
Copy link
Contributor

@hub-cap hub-cap commented Jul 23, 2018

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 elastic#32243
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Contributor

@spinscale spinscale left a 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");
Copy link
Contributor

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());
Copy link
Contributor

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) {
Copy link
Contributor

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)?

Copy link
Contributor Author

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

@hub-cap
Copy link
Contributor Author

hub-cap commented Jul 25, 2018

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

@hub-cap
Copy link
Contributor Author

hub-cap commented Jul 25, 2018

@elasticmachine test this please

@spinscale
Copy link
Contributor

testing was mostly referred to proper JSON construction (check if fields are not written if certain elements are null etc).

@@ -92,6 +92,85 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder.endObject();
}

public static IncidentEventContext parse(XContentParser parser) throws IOException {
Copy link
Contributor Author

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 {
Copy link
Contributor

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,
Copy link
Contributor

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 {
Copy link
Contributor

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
Copy link
Contributor

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();
        }

Copy link
Contributor Author

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) {
Copy link
Contributor

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());
...

Copy link
Contributor Author

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.

Copy link
Contributor

@spinscale spinscale left a 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(linkMap, is(notNullValue))

Copy link
Contributor

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

Copy link
Contributor Author

@hub-cap hub-cap Aug 2, 2018

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(imgMap, is(notNullValue))

Copy link
Contributor

@spinscale spinscale left a 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

@danielmitterdorfer
Copy link
Member

Removing the "blocker" status due to #32243 (comment).

@hub-cap hub-cap merged commit 4c90a61 into elastic:master Aug 14, 2018
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Aug 14, 2018
…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)
  ...
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Aug 14, 2018
…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)
jasontedor added a commit that referenced this pull request Aug 15, 2018
* 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)
hub-cap added a commit that referenced this pull request Aug 15, 2018
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants