-
Notifications
You must be signed in to change notification settings - Fork 158
fix: handle HTTPScaledObject not found gracefully in scaler #1488
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
base: main
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,7 @@ import ( | |||||
| "github.com/go-logr/logr" | ||||||
| "github.com/kedacore/keda/v2/pkg/scalers/externalscaler" | ||||||
| "google.golang.org/protobuf/types/known/emptypb" | ||||||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||||||
| "k8s.io/apimachinery/pkg/types" | ||||||
| "k8s.io/utils/ptr" | ||||||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||||||
|
|
@@ -200,16 +201,27 @@ func (e *impl) GetMetrics(ctx context.Context, metricRequest *externalscaler.Get | |||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| // generated the metric name for HTTPScaledObject | ||||||
| namespacedName := k8s.NamespacedNameFromNameAndNamespace(httpScaledObjectName, sor.Namespace) | ||||||
| metricName := MetricName(namespacedName) | ||||||
|
|
||||||
| httpso := &httpv1alpha1.HTTPScaledObject{} | ||||||
| if err := e.reader.Get(ctx, types.NamespacedName{Namespace: sor.Namespace, Name: httpScaledObjectName}, httpso); err != nil { | ||||||
|
Member
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. Minor nitpicks:
|
||||||
| if apierrors.IsNotFound(err) { | ||||||
| lggr.V(1).Info("HTTPScaledObject not yet available in cache, returning 0", "httpScaledObjectName", httpScaledObjectName, "namespace", sor.Namespace) | ||||||
| return &externalscaler.GetMetricsResponse{ | ||||||
| MetricValues: []*externalscaler.MetricValue{ | ||||||
| { | ||||||
| MetricName: metricName, | ||||||
| MetricValue: 0, | ||||||
| }, | ||||||
| }, | ||||||
| }, nil | ||||||
| } | ||||||
|
Comment on lines
209
to
+220
|
||||||
| lggr.Error(err, "unable to get HTTPScaledObject", "name", httpScaledObjectName, "namespace", sor.Namespace, "httpScaledObjectName", httpScaledObjectName) | ||||||
|
||||||
| lggr.Error(err, "unable to get HTTPScaledObject", "name", httpScaledObjectName, "namespace", sor.Namespace, "httpScaledObjectName", httpScaledObjectName) | |
| lggr.Error(err, "unable to get HTTPScaledObject", "name", sor.Name, "namespace", sor.Namespace, "httpScaledObjectName", httpScaledObjectName) |
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.
Nit: the comment reads "generated the metric name..." but this code is generating it now; consider changing to "generate the metric name..." for grammatical correctness (same phrasing appears in a few places in this file).