Skip to content

Add custom JSON marshaller for Alertmanager configurations #349

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

Merged
merged 2 commits into from
Jun 27, 2025

Conversation

alexander-akhmetov
Copy link
Contributor

@alexander-akhmetov alexander-akhmetov commented Jun 22, 2025

This PR adds a custom JSON marshaler (MarshalJSONWithSecrets) that can serialize Alertmanager configurations with secrets in plain text rather than masked values. It uses jsoniter to create custom encoders for secret types from Prometheus and Alertmanager.

It is not used yet.

Prometheus Alertmanager uses a few types of secret structs:

During marshaling, secrets in these structs are masked (this can be controlled only via a global variable), but sometimes we need to preserve them and this PR adds a custom marshaler for these situations.

Part of https://github.com/grafana/alerting-squad/issues/1152

@github-project-automation github-project-automation bot moved this to In review in Alerting Jun 22, 2025
@alexander-akhmetov alexander-akhmetov force-pushed the alexander-akhmetov/jsonmarshal branch 5 times, most recently from b8c96ca to 38ba2fd Compare June 22, 2025 22:08
@alexander-akhmetov alexander-akhmetov marked this pull request as ready for review June 23, 2025 08:24
@alexander-akhmetov alexander-akhmetov requested a review from a team as a code owner June 23, 2025 08:24
@alexander-akhmetov alexander-akhmetov changed the title Add a custom JSON marshaller for Alertmanager configurations Add custom JSON marshaller for Alertmanager configurations Jun 24, 2025
@alexander-akhmetov alexander-akhmetov force-pushed the alexander-akhmetov/jsonmarshal branch 2 times, most recently from e06b9d6 to e868977 Compare June 25, 2025 12:09
}

func newPlainAPI() jsoniter.API {
api := jsoniter.ConfigCompatibleWithStandardLibrary
Copy link
Contributor Author

Choose a reason for hiding this comment

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

isPtr bool
}

func (encoder *secretEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexander-akhmetov alexander-akhmetov force-pushed the alexander-akhmetov/jsonmarshal branch 2 times, most recently from 1d3b5d5 to daca488 Compare June 25, 2025 14:46
@alexander-akhmetov alexander-akhmetov force-pushed the alexander-akhmetov/jsonmarshal branch from daca488 to e5b8476 Compare June 25, 2025 14:50
Copy link
Contributor

@fayzal-g fayzal-g left a comment

Choose a reason for hiding this comment

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

Sorry for the ultra nits, logic is sound though, lgtm

Co-authored-by: Fayzal Ghantiwala <[email protected]>
@alexander-akhmetov alexander-akhmetov merged commit dc5663f into main Jun 27, 2025
6 checks passed
@alexander-akhmetov alexander-akhmetov deleted the alexander-akhmetov/jsonmarshal branch June 27, 2025 09:42
@github-project-automation github-project-automation bot moved this from In review to Done in Alerting Jun 27, 2025
stevesg pushed a commit to grafana/mimir that referenced this pull request Jun 27, 2025
#### What this PR does

Update grafana/alerting and grafana/prometheus-alertmanager modules.

[grafana/alerting
diff](grafana/alerting@3e20fda...863b097):
- grafana/alerting#347
- grafana/alerting#348
- grafana/alerting#349
 
[grafana/prometheus-alertmanager
diff](grafana/prometheus-alertmanager@92c8f63...be61a67):
- grafana/prometheus-alertmanager#117

The main change is the change of `WebhookConfig.Timeout` type from
`time.Duration` to `model.Duration` to make marshalling to JSON and YAML
the same. It does not affect YAML marshalling, only JSON and is needed
for Grafana so in the future it can start sending JSON encoded
configurations with alertmanager receivers. More details are in
grafana/prometheus-alertmanager#117

#### Checklist

- [ ] Tests updated.
- [ ] Documentation added.
- [ ] `CHANGELOG.md` updated - the order of entries should be
`[CHANGE]`, `[FEATURE]`, `[ENHANCEMENT]`, `[BUGFIX]`. If changelog entry
is not needed, please add the `changelog-not-needed` label to the PR.
- [ ]
[`about-versioning.md`](https://github.com/grafana/mimir/blob/main/docs/sources/mimir/configure/about-versioning.md)
updated with experimental features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants