Skip to content

chore: upgrade gopkg.in/yaml to v3#3322

Closed
chengjoey wants to merge 1 commit intoprometheus:mainfrom
chengjoey:chore/upgrade-yaml-3
Closed

chore: upgrade gopkg.in/yaml to v3#3322
chengjoey wants to merge 1 commit intoprometheus:mainfrom
chengjoey:chore/upgrade-yaml-3

Conversation

@chengjoey
Copy link
Contributor

use decoder.KnownFields instead of UnmarshalStrict
add MarshalYaml func for TimeInterval

#3267

use `decoder.KnownFields` instead of `UnmarshalStrict`

Signed-off-by: joey <zchengjoey@gmail.com>
@chengjoey chengjoey force-pushed the chore/upgrade-yaml-3 branch from 3b49c62 to f197517 Compare April 11, 2023 09:10
@roidelapluie
Copy link
Member

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

@chengjoey
Copy link
Contributor Author

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

never mind, there is really no problem if don't upgrade to the v3

@chengjoey chengjoey closed this Apr 11, 2023
siavashs added a commit to siavashs/alertmanager that referenced this pull request Aug 5, 2024
This change fixes the `custom_details` value in PagerDuty V2 API payloads.

Fixes prometheus#2477
Fixes prometheus#3218

Alertmanager PagerDuty configuration allows users to define `details` under `pagerduty_configs`:
```yaml
[ details: { <string>: <tmpl_string>, ... } | default = {
  firing:       '{{ template "pagerduty.default.instances" .Alerts.Firing }}'
  resolved:     '{{ template "pagerduty.default.instances" .Alerts.Resolved }}'
  num_firing:   '{{ .Alerts.Firing | len }}'
  num_resolved: '{{ .Alerts.Resolved | len }}'
} ]
```

The internal Alertmanager configuration structure is defined as:
```go
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
...
	Details        map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
}
```
And the PagerDuty payload is defined as:
```go
type pagerDutyPayload struct {
...
	CustomDetails map[string]string `json:"custom_details,omitempty"`
```

The current flow of configuration parsing and encoding is:
1. `pagerduty_configs[].details` are read from configuration as `map[string]string`
2. The `details` map values are parsed as text templates
3. `details` is encoded `custom_details` as part of the JSON payload sent to PagerDuty API V2

In the above example `.Alerts.Firing` returns a list of currently firing alert objects in this group.
Documented here: https://prometheus.io/docs/alerting/latest/notifications/#data
This results in a payload like below:
```json
{
  "client": "Alertmanager",
...
    "firing": "Labels:
 - alertname = Server_Down
...
Annotations:
 - summary = Server is down
...
",
...
}
```
Using `map[string]string` in payloads cause the rendered YAML templates to be encoded as JSON strings.
This is undesirable in most cases as the end-user might expect a nested JSON object.

This change:
- adds logic to unmarshall `details` values as YAML with fallback to string
- uses `map[string]interface{}` to encode `custom_details` to JSON
- requires gopkg.in/yaml.v3, see go-yaml/yaml#591
- does not change existing yaml.v2 dependency, see prometheus#3322

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
siavashs added a commit to siavashs/alertmanager that referenced this pull request Aug 5, 2024
This change fixes the `custom_details` value in PagerDuty V2 API payloads.

Fixes prometheus#2477
Fixes prometheus#3218

Alertmanager PagerDuty configuration allows users to define `details` under `pagerduty_configs`:
```yaml
[ details: { <string>: <tmpl_string>, ... } | default = {
  firing:       '{{ template "pagerduty.default.instances" .Alerts.Firing }}'
  resolved:     '{{ template "pagerduty.default.instances" .Alerts.Resolved }}'
  num_firing:   '{{ .Alerts.Firing | len }}'
  num_resolved: '{{ .Alerts.Resolved | len }}'
} ]
```

The internal Alertmanager configuration structure is defined as:
```go
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
...
	Details        map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
}
```
And the PagerDuty payload is defined as:
```go
type pagerDutyPayload struct {
...
	CustomDetails map[string]string `json:"custom_details,omitempty"`
```

The current flow of configuration parsing and encoding is:
1. `pagerduty_configs[].details` are read from configuration as `map[string]string`
2. The `details` map values are parsed as text templates
3. `details` is encoded `custom_details` as part of the JSON payload sent to PagerDuty API V2

In the above example `.Alerts.Firing` returns a list of currently firing alert objects in this group.
Documented here: https://prometheus.io/docs/alerting/latest/notifications/#data
This results in a payload like below:
```json
{
  "client": "Alertmanager",
...
  "custom_details": {
    "firing": "Labels:
 - alertname = Server_Down
...
Annotations:
 - summary = Server is down
...
"
    }
}
```
Using `map[string]string` in payloads cause the rendered YAML templates to be encoded as JSON strings.
This is undesirable in most cases as the end-user might expect a nested JSON object.

This change:
- adds logic to unmarshall `details` values as YAML with fallback to string
- uses `map[string]interface{}` to encode `custom_details` to JSON
- requires gopkg.in/yaml.v3, see go-yaml/yaml#591
- does not change existing yaml.v2 dependency, see prometheus#3322

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
siavashs added a commit to siavashs/alertmanager that referenced this pull request Aug 5, 2024
This change fixes the `custom_details` value in PagerDuty V2 API payloads.

Fixes prometheus#2477
Fixes prometheus#3218

Alertmanager PagerDuty configuration allows users to define `details` under `pagerduty_configs`:
```yaml
[ details: { <string>: <tmpl_string>, ... } | default = {
  firing:       '{{ template "pagerduty.default.instances" .Alerts.Firing }}'
  resolved:     '{{ template "pagerduty.default.instances" .Alerts.Resolved }}'
  num_firing:   '{{ .Alerts.Firing | len }}'
  num_resolved: '{{ .Alerts.Resolved | len }}'
} ]
```

The internal Alertmanager configuration structure is defined as:
```go
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
...
	Details        map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
}
```
And the PagerDuty payload is defined as:
```go
type pagerDutyPayload struct {
...
	CustomDetails map[string]string `json:"custom_details,omitempty"`
```

The current flow of configuration parsing and encoding is:
1. `pagerduty_configs[].details` are read from configuration as `map[string]string`
2. The `details` map values are parsed as text templates
3. The result is passed as `custom_details`, part of the JSON payload sent to PagerDuty API V2

Here is an example payload using `.Alerts.Firing`, which returns a list of currently firing alert objects in this group.
Documented here: https://prometheus.io/docs/alerting/latest/notifications/#data
This results in a payload like below:
```json
{
  "client": "Alertmanager",
...
  "custom_details": {
    "firing": "Labels:
 - alertname = Server_Down
...
Annotations:
 - summary = Server is down
...
"
    }
}
```
Using `map[string]string` in payloads cause the rendered YAML templates to be encoded as JSON strings.
This is undesirable in most cases as the end-user might expect a nested JSON object which is machine readable/parsable by it's fields.

This change:
- adds logic to unmarshall `details` values as YAML with fallback to string
- uses `map[string]interface{}` to encode `custom_details` to JSON
- requires gopkg.in/yaml.v3, see go-yaml/yaml#591
- does not change existing yaml.v2 dependency, see prometheus#3322

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
siavashs added a commit to siavashs/alertmanager that referenced this pull request Aug 5, 2024
This change fixes the `custom_details` value in PagerDuty V2 API payloads.

Fixes prometheus#2477
Fixes prometheus#3218

Alertmanager PagerDuty configuration allows users to define `details` under `pagerduty_configs`:
```yaml
[ details: { <string>: <tmpl_string>, ... } | default = {
  firing:       '{{ template "pagerduty.default.instances" .Alerts.Firing }}'
  resolved:     '{{ template "pagerduty.default.instances" .Alerts.Resolved }}'
  num_firing:   '{{ .Alerts.Firing | len }}'
  num_resolved: '{{ .Alerts.Resolved | len }}'
} ]
```

The internal Alertmanager configuration structure is defined as:
```go
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
...
	Details        map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
}
```
And the PagerDuty payload is defined as:
```go
type pagerDutyPayload struct {
...
	CustomDetails map[string]string `json:"custom_details,omitempty"`
}
```

The current flow of configuration parsing and encoding is:
1. `pagerduty_configs[].details` are read from configuration as `map[string]string`
2. The `details` map values are parsed as text templates
3. The result is passed as `custom_details`, part of the JSON payload sent to PagerDuty API V2

Here is an example payload using `.Alerts.Firing`, which returns a list of currently firing alert objects in this group.
Documented here: https://prometheus.io/docs/alerting/latest/notifications/#data
This results in a payload like below:
```json
{
  "client": "Alertmanager",
...
  "custom_details": {
    "firing": "Labels:
 - alertname = Server_Down
...
Annotations:
 - summary = Server is down
...
"
    }
}
```
Using `map[string]string` in payloads cause the rendered YAML templates to be encoded as JSON strings.
This is undesirable in most cases as the end-user might expect a nested JSON object which is machine readable/parsable by it's fields.

This change:
- adds logic to unmarshall `details` values as YAML with fallback to string
- uses `map[string]interface{}` to encode `custom_details` to JSON
- requires gopkg.in/yaml.v3, see go-yaml/yaml#591
- does not change existing yaml.v2 dependency, see prometheus#3322

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
siavashs added a commit to siavashs/alertmanager that referenced this pull request Aug 5, 2024
This change fixes the `custom_details` value in PagerDuty V2 API payloads.

Fixes prometheus#2477
Fixes prometheus#3218

Alertmanager PagerDuty configuration allows users to define `details` under `pagerduty_configs`:
```yaml
[ details: { <string>: <tmpl_string>, ... } | default = {
  firing:       '{{ template "pagerduty.default.instances" .Alerts.Firing }}'
  resolved:     '{{ template "pagerduty.default.instances" .Alerts.Resolved }}'
  num_firing:   '{{ .Alerts.Firing | len }}'
  num_resolved: '{{ .Alerts.Resolved | len }}'
} ]
```

The internal Alertmanager configuration structure is defined as:
```go
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
...
	Details        map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
}
```
And the PagerDuty payload is defined as:
```go
type pagerDutyPayload struct {
...
	CustomDetails map[string]string `json:"custom_details,omitempty"`
}
```

The current flow of configuration parsing and encoding is:
1. `pagerduty_configs[].details` are read from configuration as `map[string]string`
2. The `details` map values are parsed as text templates
3. The result is passed as `custom_details`, part of the JSON payload sent to PagerDuty API V2

Here is an example payload using `.Alerts.Firing`, which returns a list of currently firing alert objects in this group.
Documented here: https://prometheus.io/docs/alerting/latest/notifications/#data
This results in a payload like below:
```json
{
  "client": "Alertmanager",
...
  "custom_details": {
    "firing": "Labels:
 - alertname = Server_Down
...
Annotations:
 - summary = Server is down
...
"
    }
}
```
Using `map[string]string` in payloads cause the rendered YAML templates to be encoded as JSON strings.
This is undesirable in most cases as the end-user might expect a nested JSON object which is machine readable/parsable by it's fields.

This change:
- adds logic to unmarshall `details` values as YAML with fallback to string
- uses `map[string]interface{}` to encode `custom_details` to JSON
- requires gopkg.in/yaml.v3, see go-yaml/yaml#591
- does not change existing yaml.v2 dependency, see prometheus#3322

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
siavashs added a commit to siavashs/alertmanager that referenced this pull request Aug 5, 2024
This change fixes the `custom_details` value in PagerDuty V2 API payloads.

Fixes prometheus#2477
Fixes prometheus#3218

Alertmanager PagerDuty configuration allows users to define `details` under `pagerduty_configs`:
```yaml
[ details: { <string>: <tmpl_string>, ... } | default = {
  firing:       '{{ template "pagerduty.default.instances" .Alerts.Firing }}'
  resolved:     '{{ template "pagerduty.default.instances" .Alerts.Resolved }}'
  num_firing:   '{{ .Alerts.Firing | len }}'
  num_resolved: '{{ .Alerts.Resolved | len }}'
} ]
```

The internal Alertmanager configuration structure is defined as:
```go
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
...
	Details        map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
}
```
And the PagerDuty payload is defined as:
```go
type pagerDutyPayload struct {
...
	CustomDetails map[string]string `json:"custom_details,omitempty"`
}
```

The current flow of configuration parsing and encoding is:
1. `pagerduty_configs[].details` are read from configuration as `map[string]string`
2. The `details` map values are parsed as text templates
3. The result is passed as `custom_details`, part of the JSON payload sent to PagerDuty API V2

Here is an example payload using `.Alerts.Firing`, which returns a list of currently firing alert objects in this group.
Documented here: https://prometheus.io/docs/alerting/latest/notifications/#data
This results in a payload like below:
```json
{
  "client": "Alertmanager",
...
  "custom_details": {
    "firing": "Labels:
 - alertname = Server_Down
...
Annotations:
 - summary = Server is down
...
"
    }
}
```
Using `map[string]string` in payloads cause the rendered YAML templates to be encoded as JSON strings.
This is undesirable in most cases as the end-user might expect a nested JSON object which is machine readable/parsable by it's fields.

This change:
- adds logic to unmarshall `details` values as YAML with fallback to string
- uses `map[string]interface{}` to encode `custom_details` to JSON
- requires gopkg.in/yaml.v3, see go-yaml/yaml#591
- does not change existing yaml.v2 dependency, see prometheus#3322

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
siavashs added a commit to siavashs/alertmanager that referenced this pull request Aug 5, 2024
This change fixes the `custom_details` value in PagerDuty V2 API payloads.

Fixes prometheus#2477
Fixes prometheus#3218

Alertmanager PagerDuty configuration allows users to define `details` under `pagerduty_configs`:
```yaml
[ details: { <string>: <tmpl_string>, ... } | default = {
  firing:       '{{ template "pagerduty.default.instances" .Alerts.Firing }}'
  resolved:     '{{ template "pagerduty.default.instances" .Alerts.Resolved }}'
  num_firing:   '{{ .Alerts.Firing | len }}'
  num_resolved: '{{ .Alerts.Resolved | len }}'
} ]
```

The internal Alertmanager configuration structure is defined as:
```go
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
...
	Details        map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
}
```
And the PagerDuty payload is defined as:
```go
type pagerDutyPayload struct {
...
	CustomDetails map[string]string `json:"custom_details,omitempty"`
}
```

The current flow of configuration parsing and encoding is:
1. `pagerduty_configs[].details` are read from configuration as `map[string]string`
2. The `details` map values are parsed as text templates
3. The result is passed as `custom_details`, part of the JSON payload sent to PagerDuty API V2

Here is an example payload using `.Alerts.Firing`, which returns a list of currently firing alert objects in this group.
Documented here: https://prometheus.io/docs/alerting/latest/notifications/#data
This results in a payload like below:
```json
{
  "client": "Alertmanager",
...
  "custom_details": {
    "firing": "Labels:
 - alertname = Server_Down
...
Annotations:
 - summary = Server is down
...
"
    }
}
```
Using `map[string]string` in payloads cause the rendered YAML templates to be encoded as JSON strings.
This is undesirable in most cases as the end-user might expect a nested JSON object which is machine readable/parsable by it's fields.

This change:
- adds logic to unmarshall `details` values as YAML with fallback to string
- uses `map[string]interface{}` to encode `custom_details` to JSON
- requires gopkg.in/yaml.v3, see go-yaml/yaml#591
- does not change existing yaml.v2 dependency, see prometheus#3322

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
siavashs added a commit to siavashs/alertmanager that referenced this pull request Oct 13, 2025
This change fixes the `custom_details` value in PagerDuty V2 API payloads.

Fixes prometheus#2477
Fixes prometheus#3218

Alertmanager PagerDuty configuration allows users to define `details` under `pagerduty_configs`:
```yaml
[ details: { <string>: <tmpl_string>, ... } | default = {
  firing:       '{{ template "pagerduty.default.instances" .Alerts.Firing }}'
  resolved:     '{{ template "pagerduty.default.instances" .Alerts.Resolved }}'
  num_firing:   '{{ .Alerts.Firing | len }}'
  num_resolved: '{{ .Alerts.Resolved | len }}'
} ]
```

The internal Alertmanager configuration structure is defined as:
```go
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
...
	Details        map[string]string `yaml:"details,omitempty" json:"details,omitempty"`
}
```
And the PagerDuty payload is defined as:
```go
type pagerDutyPayload struct {
...
	CustomDetails map[string]string `json:"custom_details,omitempty"`
}
```

The current flow of configuration parsing and encoding is:
1. `pagerduty_configs[].details` are read from configuration as `map[string]string`
2. The `details` map values are parsed as text templates
3. The result is passed as `custom_details`, part of the JSON payload sent to PagerDuty API V2

Here is an example payload using `.Alerts.Firing`, which returns a list of currently firing alert objects in this group.
Documented here: https://prometheus.io/docs/alerting/latest/notifications/#data
This results in a payload like below:
```json
{
  "client": "Alertmanager",
...
  "custom_details": {
    "firing": "Labels:
 - alertname = Server_Down
...
Annotations:
 - summary = Server is down
...
"
    }
}
```
Using `map[string]string` in payloads cause the rendered YAML templates to be encoded as JSON strings.
This is undesirable in most cases as the end-user might expect a nested JSON object which is machine readable/parsable by it's fields.

This change:
- adds logic to unmarshall `details` values as YAML with fallback to string
- uses `map[string]interface{}` to encode `custom_details` to JSON
- requires gopkg.in/yaml.v3, see go-yaml/yaml#591
- does not change existing yaml.v2 dependency, see prometheus#3322

Signed-off-by: Siavash Safi <siavash@cloudflare.com>
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