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

Implements proper message routing logic #31

Merged
merged 9 commits into from
Apr 11, 2018

Conversation

adamnfish
Copy link
Contributor

@adamnfish adamnfish commented Apr 11, 2018

The original logic was very simplified, and now we're actually integrating a service we see that it was well short of what is required. This PR introduces "proper" contact resolution, that behaves the way people expect.

This works using a hierarchy of targets. App matches are more important than Stack matches, which are more important that AwsAccount matches. Stage must always match and is assumed to be PROD if it is omitted.

If there's an exact match between targets and a mapping then life is easy, but that won't generally be the case. We want to be able to send a message to App("myapp"). We'd also like to be able to send a message from an application that derives all the targets from its tags (e.g. App("myapp"), Stack("mystack"), AwsAccount("account-id"), Stage("STAGE")). In both case it should route messages to the "correct place". The correct place would be an exact (/close) match if it exists in the configuration, but if it hasn't been fully specified we'd still expect it to be able to send a message to the best valid match (App if that exists, falling back to Stack and then AwsAccount).

It is pretty complicated, but the logic ends up being reasonable and there are a lot of tests to capture all the edge cases. It also has a few "integration" tests that simulate more realistic invocations against a more realistic mapping configuration.

Sorry this is so complex, and such a large PR. Maybe start with the integration test section of ContactsTest and then look at the implementation.

This logic basically is Anghammarad. Sending messages to a webhook is easy, the value of a department-wide service is its ability to send messages to the correct people.

It should not depend on the order targets or mappings are specified,
particularly since the mappings are read from JSON objects (and thus
technically unordered).
This means Anghammarad can to attempt to resolve ambiguous matches
using the fact that App is more specific than Stack is more specific
than AWS Account.

Stage also gets bespoke logic. PROD is treated specially and stage is
not part of the hierarchy (it must be respected, when present).
Introduces logic for dealing with targets and applies this to improve
contact resolution.
Adds additional logic to cover the edge cases tested by ContactsTest.
These test realistic scenarios against a larger set of mappings to
simulate expected usage. Ensures that we haven't implemented all the
details and yet still missed the overall aim.
Extracts the common sort logic to a tested function
Copy link
Contributor

@katebee katebee left a comment

Choose a reason for hiding this comment

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

👍

💎 tests 👏

* Mapping has:
* Stack("stack"), App("app")
*
* This is tricky because we wouldn't to match on the following
Copy link
Contributor

Choose a reason for hiding this comment

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

This is tricky because we wouldn't to match on the following

Missing a word? 😄

This is tricky because we wouldn't want to match on the following

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great spot, thank you for reading it so carefully :-)

@adamnfish adamnfish merged commit e699b15 into master Apr 11, 2018
@adamnfish adamnfish deleted the implement-target-hierarchy branch April 11, 2018 16:33
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.

None yet

2 participants