-
Notifications
You must be signed in to change notification settings - Fork 473
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
[HPA] Add v1alpha1.MetricSpec to support for Pod custom metrics #1651
[HPA] Add v1alpha1.MetricSpec to support for Pod custom metrics #1651
Conversation
@@ -86,11 +86,17 @@ func HorizontalPodAutoscaler(cfg config.Config, logger logr.Logger, otelcol v1al | |||
}, | |||
} | |||
|
|||
if otelcol.Spec.Autoscaler != nil && otelcol.Spec.Autoscaler.Behavior != nil { | |||
if otelcol.Spec.Autoscaler.Behavior != nil { |
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.
have we confirmed that Autoscaler isn't nil by this point?
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.
Hmm there are several references of using otelcol.Spec.Autoscaler
without a nil check in this function. In fact this is the only place that nil checks. If it is unset, otelcol.Spec.Autoscaler
is created by the defaulting webhook at https://github.com/open-telemetry/opentelemetry-operator/blob/main/apis/v1alpha1/opentelemetrycollector_webhook.go#L72
So it should never be nil, but now I'm wondering if there cases where the defaulting webhook is never called and this causes a segfault?
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.
thats a good q... maybe we add the guard at the start of the function?
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.
Added the nil check at the start and returning nil if it is unset!
behavior := ConvertToV2beta2Behavior(*otelcol.Spec.Autoscaler.Behavior) | ||
autoscaler.Spec.Behavior = &behavior | ||
} | ||
|
||
// check for custom metrics | ||
if len(otelcol.Spec.Autoscaler.Metrics) > 0 { | ||
metrics := ConvertToV2Beta2PodMetrics(otelcol.Spec.Autoscaler.Metrics) |
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.
are we able to make this addition to confirm to the v2 spec to start with? Or given it's already using something similar to the v1alpha we want to keep it that way?
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.
hm maybe i'm not understanding what this should be doing. What's the type of autoscaler.Spec.Metrics
and how does that diff from what you're adding in?
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.
otelcol.Spec.Autoscaler.Metrics
has type v1alpha1.MetricSpec
this supports only the PodsMetricSource
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.
The HPA is either expecting a v2.MetricSpec
or a v2beta2.MetricSpec
so this does the necessary conversion for the HPA object depending on the version. This is something similar done for .Spec.Autoscaler.Behavior
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.
The reason I created v1alpha1.MetricSpec
instead of directly using a v2.MetricSpec
is because v2.MetricSpec
is way too large of an object for the use cases of our HPA (see https://pkg.go.dev/k8s.io/api/autoscaling/v2#MetricSpec). It supports 5 different metric types which would require a lot of validation and the deprecation of targetCPUUtilization
and targetMemoryUtilization
.
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.
v1alpha1.MetricSpec
is much smaller and can be updated as more functionality is required. I'm totally open to suggestions to change the type of otelcol.Spec.Autoscaler.Metrics
though if that's still unclear!
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.
nope, makes a ton of sense. thanks for explaining!
@@ -184,6 +185,12 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error { | |||
} | |||
} | |||
|
|||
if r.Spec.Ingress.Type == IngressTypeNginx && r.Spec.Mode == ModeSidecar { | |||
return fmt.Errorf("the OptenTelemetry Spec Ingress configuiration is incorrect. Ingress can only be used in combination with the modes: %s, %s, %s", |
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.
return fmt.Errorf("the OptenTelemetry Spec Ingress configuiration is incorrect. Ingress can only be used in combination with the modes: %s, %s, %s", | |
return fmt.Errorf("the OptenTelemetry Spec Ingress configuration is incorrect. Ingress can only be used in combination with the modes: %s, %s, %s", |
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.
Thanks for the review! Fixed.
f5e0250
to
23109cd
Compare
23109cd
to
e178a4f
Compare
…-telemetry#1651) * add to api types and validate webhook * creation of metrics * chloggen and make generate * new MetricSpec * make bundle and api-docs * lint * add webhook test case * make bundle * updates * address review feedback * gofmt * add nil check and reorder validation * fix typo * lint
Replaces #1561
This PR adds a new object
v1alpha1.MetricSpec
which is a subset of the metric types in https://pkg.go.dev/k8s.io/api/autoscaling/v2#MetricSpecCurrently
v1alpha1.MetricSpec
only supportsPodsMetricsSource
but can support more metric types in the metric array in the future. For example supportingResourceMetricsSource
in the future would allow resources to be configured in the HPA's metric array and allow us to deprecatetargetCPUUtilization
andtargetMemoryUtilization
Resolves #1560