-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver_metrics.go
More file actions
48 lines (42 loc) · 1.54 KB
/
Copy pathserver_metrics.go
File metadata and controls
48 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package dewy
import (
"context"
"time"
"go.opentelemetry.io/otel/attribute"
otelmetric "go.opentelemetry.io/otel/metric"
)
// telemetryOn reports whether telemetry is wired up and enabled. All recording
// helpers guard on it so call sites stay uncluttered.
func (d *Dewy) telemetryOn() bool {
return d.telemetry != nil && d.telemetry.Enabled()
}
// commandAttr labels a metric with the running command (server|assets|container)
// so the deployment metrics can be told apart across modes.
func (d *Dewy) commandAttr() otelmetric.MeasurementOption {
return otelmetric.WithAttributes(attribute.String("command", d.config.Command.String()))
}
// recordDeployment records the outcome of one deploy attempt. A non-nil err
// counts an error; success counts the deployment and its duration. Shared by
// the server/assets path (Run) and the container path (applyContainerDeployment)
// so every mode reports consistently.
func (d *Dewy) recordDeployment(ctx context.Context, dur time.Duration, deployErr error) {
if !d.telemetryOn() {
return
}
m := d.telemetry.Metrics()
attr := d.commandAttr()
if deployErr != nil {
m.DeploymentErrors.Add(ctx, 1, attr)
return
}
m.DeploymentsTotal.Add(ctx, 1, attr)
m.DeploymentDuration.Record(ctx, dur.Seconds(), attr)
}
// recordServerRestart counts a managed-server restart with its cause.
func (d *Dewy) recordServerRestart(ctx context.Context, reason string) {
if !d.telemetryOn() {
return
}
d.telemetry.Metrics().ServerRestarts.Add(ctx, 1,
otelmetric.WithAttributes(attribute.String("reason", reason)))
}