prometheus / alertmanager

Prometheus Alertmanager
https://prometheus.io
Apache License 2.0
6.68k stars 2.17k forks source link

alertmanager: Replace typed fields with plain string values #4083

Open jkroepke opened 4 weeks ago

jkroepke commented 4 weeks ago

Fixes #4029

The Jira API requests different fields value types depends on the custom field type itself.

Ref. https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#setting-custom-field-data-for-other-field-types, for example:

fields:
    # Components
    components: { name: "Monitoring" }
    # Custom Field TextField
    customfield_10001: "Random text"
    # Custom Field SelectList
    customfield_10002: {"value": "red"}
    # Custom Field MultiSelect
    customfield_10003: [{"value": "red"}, {"value": "blue"}, {"value": "green"}]

While jiralert allowed field values with different types as well, it might be problematic in context of the Alertmanager.

I feel that re-implement the logic from jiralert was design flaw while implement the jira notifier at Alertmanager.

WDYT: @simonpasquier @dswarbrick

dswarbrick commented 4 weeks ago

As I commented in https://github.com/prometheus/alertmanager/pull/3590#discussion_r1817166452, the need for elaborate custom YAML unmarshaling code would be avoided if Alertmanager updated to yaml.v3. I see there was an earlier PR (https://github.com/prometheus/alertmanager/pull/3322) that attempted to update this, but it was not merged because:

We have good reasons not to upgrade to v3, as common and prometheus are stuck with v2.

I see at least one other open PR (#3944) which seems to be encountering a similar scenario.

I found a little more context in this blog post about the release of yaml.v3 by its developer:

To be clear, the Go package always supported decoding into map[string]interface{} (or map[string]anything really), and that continues to work well, but if there is a map inside a map, that second map would be decoded in the most general form for lack of typing information.

This has now changed. When v3 finds a map where all the keys are strings, which is the most common scenario by far, it will automatically decode it into a map[string]interface{} type.