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

Monitoring API: Add AlertmanagerMainConfig #2148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marioferh
Copy link
Contributor

Every component will be in a separated PR in order to improve review process

First PR: #1929
Related: Enhancements Proposal openshift/enhancements#1627

Copy link
Contributor

openshift-ci bot commented Jan 15, 2025

Hello @marioferh! Some important instructions when contributing to openshift/api:
API design plays an important part in the user experience of OpenShift and as such API PRs are subject to a high level of scrutiny to ensure they follow our best practices. If you haven't already done so, please review the OpenShift API Conventions and ensure that your proposed changes are compliant. Following these conventions will help expedite the api review process for your PR.

@openshift-ci openshift-ci bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jan 15, 2025
@openshift-ci openshift-ci bot requested review from bparees and JoelSpeed January 15, 2025 14:55
Copy link
Contributor

openshift-ci bot commented Jan 15, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: marioferh
Once this PR has been reviewed and has the lgtm label, please assign knobunc for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@marioferh marioferh force-pushed the alertmanager_monitoring_api branch from c0d2965 to c35227f Compare January 15, 2025 15:21
@marioferh
Copy link
Contributor Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 15, 2025
Copy link
Contributor

openshift-ci bot commented Jan 15, 2025

@marioferh: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-serial c35227f link true /test e2e-aws-serial
ci/prow/e2e-gcp c35227f link false /test e2e-gcp
ci/prow/okd-scos-e2e-aws-ovn c35227f link false /test okd-scos-e2e-aws-ovn
ci/prow/verify-crd-schema c35227f link true /test verify-crd-schema
ci/prow/integration c35227f link true /test integration
ci/prow/e2e-aws-ovn-techpreview c35227f link true /test e2e-aws-ovn-techpreview
ci/prow/e2e-aws-serial-techpreview c35227f link true /test e2e-aws-serial-techpreview

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link

@everettraven everettraven left a comment

Choose a reason for hiding this comment

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

A lot of the comments are centered around godoc. I'd recommend looking at https://github.com/openshift/enhancements/blob/master/dev-guide/api-conventions.md#write-user-readable-documentation-in-godoc for more information on what makes a good godoc that is helpful to users.

Another thing that stood out was multiple fields related to pod spec configuration - you may want to group those into a separate struct to have a single field that clearly denotes that the sub-fields in that object map directly to pod spec fields.

@@ -77,6 +78,9 @@ type ClusterMonitoringSpec struct {
// userDefined set the deployment mode for user-defined monitoring in addition to the default platform monitoring.
// +required
UserDefined UserDefinedMonitoring `json:"userDefined"`
// alertmanagerMainConfig defines settings for the Alertmanager component in the `openshift-monitoring` namespace.

Choose a reason for hiding this comment

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

While this is a good start in stating what this field does, generally it is recommended to follow the guidelines for writing godoc on the API fields here: https://github.com/openshift/enhancements/blob/master/dev-guide/api-conventions.md#write-user-readable-documentation-in-godoc

In particular, the changes I would suggest here are:

  • Making sure there is a clear explanation as to why a user may want to use this field (i.e what does it allow them to achieve?)
  • including a reference that the field is required. Users can't see the +required marker in the generated documentation that is shown when using something like oc explain ... so being explicit in the godoc ensures that a user will see that information.

Comment on lines +112 to +113
// mode enables or disables the main Alertmanager instance. in the `openshift-monitoring` namespace
// Allowed values are "Enabled", "Disabled".

Choose a reason for hiding this comment

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

A few things:

  • It would be good to go a bit more in detail on what this actually does when set to a specific value. What actually happens when this is set to Enabled?
  • Include a snippet that this field is required, as per my previous comment about tags not being included in generated documentation
  • Generally we try to avoid using Enabled and Disabled as they can be a bit overloaded and similar to True/False. This makes it a bit more difficult to introduce additional modes in the future where it isn't necessarily a clean enabled/disabled. Are there any other names you could use that are more descriptive for the same desired state?

type AlertmanagerMainConfig struct {
// mode enables or disables the main Alertmanager instance. in the `openshift-monitoring` namespace
// Allowed values are "Enabled", "Disabled".
// +kubebuilder:validation:Enum:=Enabled;Disabled;""

Choose a reason for hiding this comment

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

It looks like this validation includes the ability to use an empty string as a value. There is no mention that the empty value is a valid value - is it?

If it is, is this actually a required field? What happens in the case of the empty string value?

}

// AlertmanagerMode defines mode for AlertManager instance
// +kubebuilder:validation:Enum="";Enabled;Disabled

Choose a reason for hiding this comment

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

This is a repeated enum validation that exists on the AlertmanagerMainConfig.Mode field. This results in two separate enum validations showing up on the generated CRD that may result in unexpected behavior. Maintaining two separate validations may also introduce drift.

Pick one location to add this validation.


const (
// AlertManagerEnable enables the main Alertmanager instance. in the `openshift-monitoring` namespace
AlertManagerEnabled AlertManagerMode = "Enabled"

Choose a reason for hiding this comment

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

Generally, it is recommended to have these constants follow a pattern of type name followed by the value. In this case it should be:

Suggested change
AlertManagerEnabled AlertManagerMode = "Enabled"
AlertManagerModeEnabled AlertManagerMode = "Enabled"

// /etc/alertmanager/secrets/<secret-name> within the 'alertmanager' container of
// the Alertmanager Pods.
// +optional
Secrets []string `json:"secrets,omitempty"`

Choose a reason for hiding this comment

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

For local object references, the api convention is to create a type alias. A good example is in the OpenShift API conventions doc under https://github.com/openshift/enhancements/blob/master/dev-guide/api-conventions.md#use-specific-types-for-object-references-and-omit-ref-suffix

// They will be added as volumes named secret-<secret-name> and mounted at
// /etc/alertmanager/secrets/<secret-name> within the 'alertmanager' container of
// the Alertmanager Pods.
// +optional

Choose a reason for hiding this comment

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

Mention that the field is optional in the godoc

Comment on lines +142 to +143
// tolerations Defines tolerations for the pods.
// +optional

Choose a reason for hiding this comment

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

Include the field is optional in the godoc. Elaborate further on the field, including what it does, why a user may care, etc.

Comment on lines +145 to +146
// topologySpreadConstraints Defines a pod's topology spread constraints.
// +optional

Choose a reason for hiding this comment

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

Same general comments regarding godoc updates.

Comment on lines +148 to +151
// volumeClaimTemplate Defines persistent storage for Alertmanager. Use this setting to
// configure the persistent volume claim, including storage class, volume
// size, and name.
// +optional

Choose a reason for hiding this comment

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

Mention the field is optional in the godoc. What happens when this field is unset?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants