-
Notifications
You must be signed in to change notification settings - Fork 524
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ limitations under the License. | |||||||||||||
package v1 | ||||||||||||||
|
||||||||||||||
import ( | ||||||||||||||
v1 "k8s.io/api/core/v1" | ||||||||||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
|
@@ -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. | ||||||||||||||
// +required | ||||||||||||||
AlertmanagerMainConfig AlertmanagerMainConfig `json:"alertmanagerMainConfig"` | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// UserDefinedMonitoring config for user-defined projects. | ||||||||||||||
|
@@ -101,3 +105,86 @@ const ( | |||||||||||||
// UserDefinedNamespaceIsolated enables monitoring for user-defined projects with namespace-scoped tenancy. This ensures that metrics, alerts, and monitoring data are isolated at the namespace level. | ||||||||||||||
UserDefinedNamespaceIsolated UserDefinedMode = "NamespaceIsolated" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
// The `AlertmanagerMainConfig` resource defines settings for the | ||||||||||||||
// Alertmanager component in the `openshift-monitoring` namespace. | ||||||||||||||
type AlertmanagerMainConfig struct { | ||||||||||||||
// mode enables or disables the main Alertmanager instance. in the `openshift-monitoring` namespace | ||||||||||||||
// Allowed values are "Enabled", "Disabled". | ||||||||||||||
Comment on lines
+112
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few things:
|
||||||||||||||
// +kubebuilder:validation:Enum:=Enabled;Disabled;"" | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||||||||||||||
// +required | ||||||||||||||
Mode AlertManagerMode `json:"mode"` | ||||||||||||||
// userMode enables or disables user-defined namespaces | ||||||||||||||
// to be selected for `AlertmanagerConfig` lookups. This setting only | ||||||||||||||
// applies if the user workload monitoring instance of Alertmanager | ||||||||||||||
// is not enabled. | ||||||||||||||
Comment on lines
+117
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few things:
|
||||||||||||||
// +required | ||||||||||||||
UserMode UserAlertManagerMode `json:"userMode"` | ||||||||||||||
// logLevel Defines the log level setting for Alertmanager. | ||||||||||||||
// The possible values are: `Error`, `Warn`, `Info`, `Debug`. | ||||||||||||||
// The default value is `Info`. | ||||||||||||||
Comment on lines
+123
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few things:
|
||||||||||||||
// +optional | ||||||||||||||
// +kubebuilder:default=Info | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OpenAPI generation doesn't understand the kubebuilder default tag. Use |
||||||||||||||
LogLevel string `json:"logLevel,omitempty"` | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally when using an enum it is recommended to use a type alias. This field is also missing an enum marker. |
||||||||||||||
// nodeSelector Defines the nodes on which the Pods are scheduled. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to explain more about what is done with the values in this field and why a user might care. Is this field passed directly to the Pod spec for node selection? Also include that this field is optional in the godoc and what happens if it is not specified. |
||||||||||||||
// +optional | ||||||||||||||
NodeSelector map[string]string `json:"nodeSelector,omitempty"` | ||||||||||||||
// resources Defines resource requests and limits for the Alertmanager container. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would recommend expanding on the godoc a bit more here. Include that it is optional and what happens if not set. Should there be a default? Why would a user care to use this field? How is the value of this field used? |
||||||||||||||
// +optional | ||||||||||||||
Resources *v1.ResourceRequirements `json:"resources,omitempty"` | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like it would be passed directly to the pod spec, but it is worth considering - are you okay with relying on an external API, including any and all maintenance challenges involved in that? |
||||||||||||||
// secrets Defines a list of secrets that need to be mounted into the Alertmanager. | ||||||||||||||
// The secrets must reside within the same namespace as the Alertmanager object. | ||||||||||||||
// 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 | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mention that the field is optional in the godoc |
||||||||||||||
Secrets []string `json:"secrets,omitempty"` | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||||||||||
// tolerations Defines tolerations for the pods. | ||||||||||||||
// +optional | ||||||||||||||
Comment on lines
+142
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||||||||
Tolerations []v1.Toleration `json:"tolerations,omitempty"` | ||||||||||||||
// topologySpreadConstraints Defines a pod's topology spread constraints. | ||||||||||||||
// +optional | ||||||||||||||
Comment on lines
+145
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same general comments regarding godoc updates. |
||||||||||||||
TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` | ||||||||||||||
Comment on lines
+129
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This generally looks like a bunch of configuration options that are going to be piped directly to a Pod spec. Would it make more sense to put these under a new type to group all of these options under a field named something like podTemplate to make it more clear that these values get stamped directly onto the Alertmanager Pod? |
||||||||||||||
// volumeClaimTemplate Defines persistent storage for Alertmanager. Use this setting to | ||||||||||||||
// configure the persistent volume claim, including storage class, volume | ||||||||||||||
// size, and name. | ||||||||||||||
// +optional | ||||||||||||||
Comment on lines
+148
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||||||||||||||
VolumeClaimTemplate v1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"` | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// AlertmanagerMode defines mode for AlertManager instance | ||||||||||||||
// +kubebuilder:validation:Enum="";Enabled;Disabled | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a repeated enum validation that exists on the Pick one location to add this validation. |
||||||||||||||
type AlertManagerMode string | ||||||||||||||
|
||||||||||||||
const ( | ||||||||||||||
// AlertManagerEnable enables the main Alertmanager instance. in the `openshift-monitoring` namespace | ||||||||||||||
AlertManagerEnabled AlertManagerMode = "Enabled" | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||||||||
// AlertManagerDisabled enables the main Alertmanager instance. in the `openshift-monitoring` namespace | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? |
||||||||||||||
AlertManagerDisabled AlertManagerMode = "Disabled" | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above:
Suggested change
|
||||||||||||||
) | ||||||||||||||
|
||||||||||||||
// UserAlertManagerMode defines mode for user-defines namespaced | ||||||||||||||
// +kubebuilder:validation:Enum="";Enabled;Disabled | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UserMode looks to be a required field, is the empty string actually a valid value? If so, what happens in the case the empty value is provided? |
||||||||||||||
type UserAlertManagerMode string | ||||||||||||||
|
||||||||||||||
const ( | ||||||||||||||
// AlertManagerEnabled enables user-defined namespaces to be selected for `AlertmanagerConfig` lookups. This setting only | ||||||||||||||
// applies if the user workload monitoring instance of Alertmanager is not enabled. | ||||||||||||||
UserAlertManagerEnabled UserAlertManagerMode = "Enabled" | ||||||||||||||
Comment on lines
+171
to
+173
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
// AlertManagerDisabled disables user-defined namespaces to be selected for `AlertmanagerConfig` lookups. This setting only | ||||||||||||||
// applies if the user workload monitoring instance of Alertmanager is not enabled. | ||||||||||||||
UserAlertManagerDisabled UserAlertManagerMode = "Disabled" | ||||||||||||||
Comment on lines
+174
to
+176
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
) | ||||||||||||||
|
||||||||||||||
// +kubebuilder:validation:Enum="";Error;Warn;Info;Debug | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is an empty string a valid log level value? What should happen when set to the empty string value? |
||||||||||||||
type LogLevel string | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be at least some godoc here to explain what this type is for. |
||||||||||||||
|
||||||||||||||
var ( | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be constants |
||||||||||||||
Error LogLevel = "error" | ||||||||||||||
|
||||||||||||||
Warn LogLevel = "warn" | ||||||||||||||
|
||||||||||||||
Info LogLevel = "info" | ||||||||||||||
|
||||||||||||||
Debug LogLevel = "debug" | ||||||||||||||
Comment on lines
+183
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The string values here should be capitalized to match the enum values. Each should generally follow the name pattern of |
||||||||||||||
) |
There was a problem hiding this comment.
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:
+required
marker in the generated documentation that is shown when using something likeoc explain ...
so being explicit in the godoc ensures that a user will see that information.