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

alertmanager: Replace typed fields with plain string values #4083

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jkroepke
Copy link
Contributor

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.

  • A new dependency github.com/trivago/tgo was necessary to cast all keys to strings. Ref. jira integration #3590 (comment)
  • Looking at Prometheus Operator, Kubernetes CRDs doesn't support such flexible types, because type is not allowed inside anyOf. From Kubernetes point of view, all field values must be declared as string and an additional transformation logic is necessary to convert string values to complex values.

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

WDYT: @simonpasquier @dswarbrick

@jkroepke jkroepke marked this pull request as draft October 25, 2024 12:35
@dswarbrick
Copy link

dswarbrick commented Oct 25, 2024

As I commented in #3590 (comment), the need for elaborate custom YAML unmarshaling code would be avoided if Alertmanager updated to yaml.v3. I see there was an earlier PR (#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.

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