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

crd: add support for source pagerduty_config option in AlertMananger CRD #6427

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

codeknight03
Copy link
Contributor

The AlertManager CRD was expected to have 1:1 fields mapped from https://prometheus.io/docs/alerting/latest/configuration/#pagerduty_config . Currently source was missing so it is added.

Closes #6387

Description

Added Source in v1alpha1 and v1beta1 altermanager_config_types and added the necessary code in amcfg.go

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Verification

I ran package specific tests for alertmanager package for the pagerduty config method. Here is the command :

go test -run ^TestSanitizePagerDutyConfig$ ./pkg/alertmanager 

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

Add source pagerduty config option to AlertManager CRD.

The AlertManager CRD was expected to have 1:1 fields mapped from
https://prometheus.io/docs/alerting/latest/configuration/#pagerduty_config
. Currently source was missing so it is added.

Fixes prometheus-operator#6387
@codeknight03 codeknight03 requested a review from a team as a code owner March 23, 2024 22:33
@slashpai
Copy link
Contributor

Can you add unit test as well?

@pull-request-size pull-request-size bot added size/M and removed size/S labels Mar 25, 2024
@codeknight03
Copy link
Contributor Author

codeknight03 commented Mar 25, 2024

@slashpai , Added the unit test for checking source gets added in case of supported versions.
Checked the unit test was working by running the following commands :

go test -run ^TestSanitizePagerDutyConfig$ ./pkg/alertmanager

go test ./pkg/alertmanager

Thanks a lot.

Co-authored-by: Jayapriya Pai <slashpai9@gmail.com>
@slashpai
Copy link
Contributor

You would need regenerate and update the code as well as type is changed to pointer

@codeknight03
Copy link
Contributor Author

codeknight03 commented Mar 26, 2024

Yeah I am making the changes locally. But looking at it in details I see @simonpasquier chose it to be a string , I think Source is not an optional field but has a default value set (confusing me to believe it is optional). Here is a screenshot from https://prometheus.io/docs/alerting/latest/configuration/#pagerduty_config

image

I think I should rather change it from optional to not being optional. Might need help. Thank you for all the patience you've had with me.

@simonpasquier
Copy link
Contributor

I think Source is not an optional field but has a default value set (confusing me to believe it is optional).

no source doesn't have to be defined by the user so it needs to be a *string as @slashpai pointed out.

@codeknight03
Copy link
Contributor Author

Updated the changes to make source be the string pointer type since it is an optional field. Tested it out with E2E tests on local and unit tests.

Copy link
Contributor

@slashpai slashpai left a comment

Choose a reason for hiding this comment

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

just a nit lgtm otherwise
Thanks for working on this

pkg/alertmanager/amcfg_test.go Outdated Show resolved Hide resolved
pkg/alertmanager/amcfg_test.go Outdated Show resolved Hide resolved
@codeknight03
Copy link
Contributor Author

@slashpai I have not removed the sourceVal variable to allow to check if the same pointer is being received or not. Though I have changed the way of obtaining the pointer.

Thanks a lot for all the patience this has been one of the best experiences of contributing to any Open Source project.

@codeknight03
Copy link
Contributor Author

codeknight03 commented Apr 1, 2024

I don't see why the tests are failing, as they working previously and I haven't changed anything regarding the tests that failed. @mviswanathsai, do you think you can help me with this one ?

@slashpai Also I see that these checks are not in the required category anyway I can run them again to check if this was an incidental failure ?

@mviswanathsai
Copy link
Contributor

The test that is failing is often flaky. Rerunning the checks should sort this out.

@codeknight03
Copy link
Contributor Author

Will be making changes as soon as possible. Working on them

@codeknight03
Copy link
Contributor Author

Hi @slashpai and @simonpasquier . Would you guys like me to make any further changes on this one ?

Copy link
Contributor

@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.

Thanks! We need also changes here

func convertPagerDutyConfigFrom(in v1alpha1.PagerDutyConfig) PagerDutyConfig {
return PagerDutyConfig{
SendResolved: in.SendResolved,
RoutingKey: convertSecretKeySelectorFrom(in.RoutingKey),
ServiceKey: convertSecretKeySelectorFrom(in.ServiceKey),
URL: in.URL,
Client: in.Client,
ClientURL: in.ClientURL,
Description: in.Description,
Severity: in.Severity,
Class: in.Class,
Group: in.Group,
Component: in.Component,
Details: convertKeyValuesFrom(in.Details),
PagerDutyImageConfigs: convertPagerDutyImageConfigsFrom(in.PagerDutyImageConfigs),
PagerDutyLinkConfigs: convertPagerDutyLinkConfigsFrom(in.PagerDutyLinkConfigs),
HTTPConfig: convertHTTPConfigFrom(in.HTTPConfig),
}
}

func convertPagerDutyConfigTo(in PagerDutyConfig) v1alpha1.PagerDutyConfig {
return v1alpha1.PagerDutyConfig{
SendResolved: in.SendResolved,
RoutingKey: convertSecretKeySelectorTo(in.RoutingKey),
ServiceKey: convertSecretKeySelectorTo(in.ServiceKey),
URL: in.URL,
Client: in.Client,
ClientURL: in.ClientURL,
Description: in.Description,
Severity: in.Severity,
Class: in.Class,
Group: in.Group,
Component: in.Component,
Details: convertKeyValuesTo(in.Details),
PagerDutyImageConfigs: convertPagerDutyImageConfigsTo(in.PagerDutyImageConfigs),
PagerDutyLinkConfigs: convertPagerDutyLinkConfigsTo(in.PagerDutyLinkConfigs),
HTTPConfig: convertHTTPConfigTo(in.HTTPConfig),
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support all pagerduty_config options in AlertmanagerConfig crd
5 participants