-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add metric and logging for activator-autoscaler connectivity #16318
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
Changes from 4 commits
dce652d
1e54a49
0a216b5
59d3df8
485a37a
b8ef157
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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| Copyright 2024 The Knative Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package activator | ||
|
|
||
| import ( | ||
| "go.opentelemetry.io/otel" | ||
| "go.opentelemetry.io/otel/metric" | ||
| ) | ||
|
|
||
| var scopeName = "knative.dev/serving/pkg/activator" | ||
|
|
||
| type statReporterMetrics struct { | ||
| autoscalerReachable metric.Int64Gauge | ||
| autoscalerConnectionErrors metric.Int64Counter | ||
| } | ||
|
|
||
| func newStatReporterMetrics(mp metric.MeterProvider) *statReporterMetrics { | ||
| var ( | ||
| m statReporterMetrics | ||
| err error | ||
| provider = mp | ||
| ) | ||
|
|
||
| if provider == nil { | ||
| provider = otel.GetMeterProvider() | ||
| } | ||
|
|
||
| meter := provider.Meter(scopeName) | ||
|
|
||
| m.autoscalerReachable, err = meter.Int64Gauge( | ||
|
||
| "kn.activator.autoscaler.reachable", | ||
|
||
| metric.WithDescription("Whether the autoscaler is reachable from the activator (1 = reachable, 0 = not reachable)"), | ||
| metric.WithUnit("{reachable}"), | ||
| ) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| m.autoscalerConnectionErrors, err = meter.Int64Counter( | ||
| "kn.activator.autoscaler.connection_errors_total", | ||
|
||
| metric.WithDescription("Total number of autoscaler connection errors from the activator"), | ||
| metric.WithUnit("{error}"), | ||
| ) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| return &m | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -17,9 +17,18 @@ limitations under the License. | |||
| package activator | ||||
|
|
||||
| import ( | ||||
| "context" | ||||
| "time" | ||||
|
|
||||
| "github.com/gorilla/websocket" | ||||
| "go.opentelemetry.io/otel/metric" | ||||
| "go.uber.org/zap" | ||||
| "knative.dev/serving/pkg/autoscaler/metrics" | ||||
| asmetrics "knative.dev/serving/pkg/autoscaler/metrics" | ||||
| ) | ||||
|
|
||||
| const ( | ||||
| // connectionCheckInterval is how often to check the autoscaler connection status. | ||||
| connectionCheckInterval = 5 * time.Second | ||||
| ) | ||||
|
|
||||
| // RawSender sends raw byte array messages with a message type | ||||
|
|
@@ -28,21 +37,57 @@ type RawSender interface { | |||
| SendRaw(msgType int, msg []byte) error | ||||
| } | ||||
|
|
||||
| // StatusChecker checks the connection status. | ||||
| type StatusChecker interface { | ||||
| Status() error | ||||
| } | ||||
|
|
||||
| // AutoscalerConnectionStatusMonitor periodically checks if the autoscaler is reachable | ||||
| // and emits metrics and logs accordingly. | ||||
| func AutoscalerConnectionStatusMonitor(ctx context.Context, logger *zap.SugaredLogger, conn StatusChecker, mp metric.MeterProvider) { | ||||
|
||||
| const reportInterval = time.Second |
This means errors would be detected there already.
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.
Good point! You're right that errors are already detected every second via ReportStats when stats are being sent. However, the monitor handles one edge case: when there's no traffic. If no requests are coming in, ConcurrencyReporter sends nothing (len(msgs) == 0), so ReportStats never calls SendRaw(), and we wouldn't detect a broken connection.
Uh oh!
There was an error while loading. Please reload this page.