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

adds general purpose event webhook #401

Merged
merged 12 commits into from
Jan 11, 2020
Merged

Conversation

mrparkers
Copy link
Contributor

context: #393

opening this as a draft PR so I can get feedback on the implementation. if this is the correct path to go, I'll add some test cases.

@mrparkers
Copy link
Contributor Author

@stefanprodan I went ahead and added this as a command line flag instead of a webhook for the Canary resource because I wanted to globally configure flagger to always send events to a webhook instead of doing it individually for each Canary - hope that implementation is alright with you

@stefanprodan
Copy link
Member

Can you post here the JSON that gets sent?

@mrparkers
Copy link
Contributor Author

Sure, here's an example:

{
  metadata: {
    name: 'marketsummary.15e76cd80a706334',
    namespace: 'parker-lab-staging',
    creationTimestamp: null
  },
  involvedObject: {
    kind: 'Canary',
    namespace: 'parker-lab-staging',
    name: 'marketsummary',
    uid: '2d2bfe68-2e78-11ea-b1d3-0e68aa341cb7',
    apiVersion: 'flagger.app/v1alpha3',
    resourceVersion: '24563926'
  },
  reason: 'Synced',
  message: 'Starting canary analysis for marketsummary.parker-lab-staging',
  source: { component: 'flagger' },
  firstTimestamp: null,
  lastTimestamp: null,
  type: 'Normal',
  eventTime: null,
  reportingComponent: '',
  reportingInstance: ''
}

@stefanprodan
Copy link
Member

stefanprodan commented Jan 7, 2020

I would like to standardise the webhook calls based the current payload object, right now it looks like this:

{
    "name": "podinfo",
    "namespace": "test",
    "phase": "Progressing", 
    "metadata": {
        "key1":  "val1",
        "key2":  "val2",
    }
}

I would just add the timestamp, message and event type to the metadata. What do you think?

@mrparkers
Copy link
Contributor Author

mrparkers commented Jan 7, 2020

I don't mind changing the schema for this, but would it be okay to include involvedObject as well? I need to have a reference to the Canary object that flagger is acting upon.

Or perhaps I'm misunderstanding - in the JSON you posted, does name refer to the Canary object? If so, I can definitely use that schema.

@stefanprodan
Copy link
Member

Well that's what the current payload has, the canary name, namespace and current phase.

@stefanprodan
Copy link
Member

@mrparkers
Copy link
Contributor Author

Perfect, I'll use that schema then. Thanks for the feedback!

@stefanprodan
Copy link
Member

I think the global webhook address could be override by a webhook of type event when present in the canary spec but this can be address at a later time.

@mrparkers
Copy link
Contributor Author

@stefanprodan I updated the event payload schema:

{
  name: 'marketsummary',
  namespace: 'parker-lab-staging',
  phase: 'Progressing',
  metadata: {
    eventMessage: 'Advance marketsummary.parker-lab-staging canary weight 75',
    eventType: 'Normal',
    timestamp: '1578417122726798559'
  }
}

The only issue I had when testing is that the "New revision detected" event is sent to the webhook with a phase of "Succeeded" instead of "Progressing". I tried to fix this by moving these lines below c.recorder.SetStatus but that didn't seem to fix it.

I don't personally mind this but I'm willing to dig deeper into this if you'd like me to. Although I could use a few tips for what to look at.

@mrparkers
Copy link
Contributor Author

@stefanprodan I went ahead and marked the PR as "ready for review". please let me know if you're okay with this approach and I can write some tests for what I did.

@mrparkers mrparkers marked this pull request as ready for review January 8, 2020 23:25
@stefanprodan
Copy link
Member

@mrparkers SetStatus changes the status in cluster but it doesn't alter the canary in-memory copy. I don't think we should move the notification function from where it is, instead we could make a deep copy of the canary object, change the status in-line and send that copy to the notification function.

@stefanprodan
Copy link
Member

@mrparkers the PR looks good, besides tests I think we also need to document how this works and give some json examples.

@mrparkers
Copy link
Contributor Author

@stefanprodan added tests and docs

Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @mrparkers awesome work!

@stefanprodan stefanprodan merged commit 0082b33 into fluxcd:master Jan 11, 2020
@mrparkers mrparkers deleted the event-webhook branch January 11, 2020 21:49
@stefanprodan stefanprodan mentioned this pull request Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants