Skip to content

Support adding custom fields to VictorOps notifications#1420

Merged
stuartnelson3 merged 6 commits intoprometheus:masterfrom
jay-rob:victorop-custom-fields
Jan 15, 2019
Merged

Support adding custom fields to VictorOps notifications#1420
stuartnelson3 merged 6 commits intoprometheus:masterfrom
jay-rob:victorop-custom-fields

Conversation

@jay-rob
Copy link

@jay-rob jay-rob commented Jun 16, 2018

This PR is a followup to another PR that was opened #1315.

These changes allow users to define additional fields they would like to pass on to VictorOps and use templates to set the values of those fields.

Example:

- name: default
  victorops_configs:
  - entity_display_name: '{{ .CommonAnnotations.summary}}'
    message_type: '{{ .CommonLabels.severity }}'
    routing_key: default
    state_message: '{{ .CommonAnnotations.description }}'
    custom_fields:
      tier: '{{ .CommonLabels.tier }}'
      storage: '{{ .CommonLabels.storage }}'

Logic has been added to prevent a custom field colliding with/overriding a statically defined field. When this occurs, the field will simply be ignored and a debug level log message will notify of this.

@jay-rob jay-rob force-pushed the victorop-custom-fields branch 2 times, most recently from 48efbb4 to 5a9deb0 Compare June 17, 2018 14:00
Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

A few comments but looks good overall.

notify/impl.go Outdated
return n.retry(resp.StatusCode)
}

//Create the json payload to be sent to victorops api
Copy link
Member

Choose a reason for hiding this comment

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

(nit) add a space before Create + missing dot + s/json/JSON/

Copy link
Author

Choose a reason for hiding this comment

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

fixed the space. whats the second part about the DOT?

notify/impl.go Outdated
return nil, fmt.Errorf("templating error: %s", err)
}
} else {
level.Debug(n.logger).Log("msg", "Ignoring custom field %q as it is already defined as a fixed field", "omitted_field", k, "incident", key)
Copy link
Member

Choose a reason for hiding this comment

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

You need to remove the %q formatter in the message.

level.Debug(n.logger).Log("msg", "Ignoring custom field as it is already defined as a fixed field", "field", k, "incident", key)

@jay-rob
Copy link
Author

jay-rob commented Jun 18, 2018

Thank you for the feedback @simonpasquier . I have incorporated the changes

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

Still a few minor nits. I guess you have the opportunity to test the change against the VictorOps API?

notify/impl.go Outdated
return n.retry(resp.StatusCode)
}

// Create the json payload to be sent to victorops api
Copy link
Member

Choose a reason for hiding this comment

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

missing dot

Copy link
Member

Choose a reason for hiding this comment

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

Either add a dot at the end or simply remove the comment since it is pretty clear from the function name what it is doing.

//Verify the invalid custom field didn't override the static field
require.Equal(t, "message", m["state_message"])

//Verify that a custom field was added to the payload and templatized
Copy link
Member

Choose a reason for hiding this comment

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

missing space and dot

@jay-rob jay-rob force-pushed the victorop-custom-fields branch from 93f5a70 to 31a0576 Compare June 23, 2018 23:00
@jay-rob
Copy link
Author

jay-rob commented Jun 23, 2018

Sorry for the delay. I went ahead and added validation to the config load logic of Victorops. I left the notifier logic in place, it felt appropriate to keep it there as an extra safety net. Thanks for the feedback @brian-brazil

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

Only a few comments.

MonitoringTool: `AM`,
CustomFields: map[string]string{
"Field_A": "{{ .CommonLabels.Message }}",
//A field that should be ignored
Copy link
Member

Choose a reason for hiding this comment

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

L291-292 to be removed

@jay-rob jay-rob force-pushed the victorop-custom-fields branch from 9561337 to e32e5d0 Compare June 26, 2018 16:06
Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

A few minor comments otherwise LGTM.

* [CHANGE] Validate Slack field config and only allow the necessary input (#1334)
* [CHANGE] Remove legacy alert ingest endpoint (#1362)
* [CHANGE] Moved to memberlist as underlying gossip protocol
* [CHANGE] Move to memberlist as underlying gossip protocol including cluster flag changes from --mesh.xxx to --cluster.xxx (#1232)
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why you got this change included.

notify/impl.go Outdated
return n.retry(resp.StatusCode)
}

// Create the json payload to be sent to victorops api
Copy link
Member

Choose a reason for hiding this comment

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

Either add a dot at the end or simply remove the comment since it is pretty clear from the function name what it is doing.

@sta-szek
Copy link

sta-szek commented Dec 3, 2018

Hi, any progress here? I would like to use that feature. :)

@simonpasquier
Copy link
Member

@jrthrawny can you resolve the conflicts and address the comments?

@valery-lezhebokov
Copy link

Hi,
I would be interested in that feature too.

@jay-rob
Copy link
Author

jay-rob commented Dec 8, 2018

Hello. I will rebase this PR and incorporate the changes suggested in feedback

Signed-off-by: Jason Roberts <jroberts@drud.com>
Signed-off-by: Jason Roberts <jroberts@drud.com>
Signed-off-by: Jason Roberts <jroberts@drud.com>
Signed-off-by: Jason Roberts <jroberts@drud.com>
Signed-off-by: Jason Roberts <jroberts@drud.com>
@jay-rob jay-rob force-pushed the victorop-custom-fields branch from e32e5d0 to 4952cc0 Compare December 10, 2018 04:28
@jay-rob
Copy link
Author

jay-rob commented Dec 10, 2018

I've rebased this from master and cleaned up the comment grammar. Let me know if there is anything else I need to do. Sorry again for the delay

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

LGTM. Only one small remark on a comment.

notify/impl.go Outdated
return n.retry(resp.StatusCode)
}

// Create the json payload to be sent to victorops api.
Copy link
Member

Choose a reason for hiding this comment

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

s/json/JSON/
s/victorops api/the VictorOps API/

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, just pushed the fix

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

You miss the DCO on the last commit otherwise 👍

Signed-off-by: Jason Roberts <jroberts@drud.com>
@jay-rob jay-rob force-pushed the victorop-custom-fields branch from 4d0a73f to b23f2c6 Compare December 10, 2018 16:01
@jay-rob
Copy link
Author

jay-rob commented Dec 11, 2018

signed :)

@stuartnelson3 stuartnelson3 merged commit b02afca into prometheus:master Jan 15, 2019
@stuartnelson3
Copy link
Contributor

Just saw this! Maybe @mxinden can add it to the 0.16.0 beta pr :)

mxinden pushed a commit to mxinden/alertmanager that referenced this pull request Jan 15, 2019
)

* Support adding custom fields to VictorOps notifications

* Response to feedback

* Added logic to validate victorops custom fields to config load time

* Cleanup victorops notifier of logic duplicated in config check

* rebase and further cleanup from feedback

* another grammer fix

Signed-off-by: Jason Roberts <jroberts@drud.com>
@mxinden
Copy link
Member

mxinden commented Jan 15, 2019

Thanks for the pointer @stuartnelson3. Added to #1708.

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.

7 participants