Skip to content

Commit 60c00f6

Browse files
committed
Update otel to 0.13.0
This updates the dependency to the latest release: 0.13.0
1 parent 88509ac commit 60c00f6

File tree

7 files changed

+224
-82
lines changed

7 files changed

+224
-82
lines changed

cmd/secrets-store-csi-driver/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,10 @@ func main() {
7979
// Issue: https://github.com/open-telemetry/opentelemetry-go/issues/677
8080
// this has been resolved in otel release v0.5.0
8181
// TODO (aramase) update to latest version of otel and deps
82-
m, err := metrics.NewMetricsExporter()
82+
err := metrics.InitMetricsExporter()
8383
if err != nil {
8484
klog.Fatalf("failed to initialize metrics exporter, error: %+v", err)
8585
}
86-
defer m.Stop()
8786

8887
config := ctrl.GetConfigOrDie()
8988
config.UserAgent = "csi-secrets-store/controller"

go.mod

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ require (
66
github.com/blang/semver v3.5.0+incompatible
77
github.com/container-storage-interface/spec v1.0.0
88
github.com/go-logr/logr v0.2.1 // indirect
9-
github.com/golang/protobuf v1.4.2
10-
github.com/google/go-cmp v0.5.0
9+
github.com/golang/protobuf v1.4.3
10+
github.com/google/go-cmp v0.5.2
1111
github.com/kubernetes-csi/csi-lib-utils v0.6.1
1212
github.com/kubernetes-csi/csi-test v1.1.0
1313
github.com/onsi/gomega v1.10.1
14-
github.com/stretchr/testify v1.5.1
15-
go.opentelemetry.io/otel v0.4.3
16-
go.opentelemetry.io/otel/exporters/metric/prometheus v0.4.3
14+
github.com/prometheus/client_golang v1.8.0 // indirect
15+
github.com/stretchr/testify v1.6.1
16+
go.opentelemetry.io/otel v0.13.0
17+
go.opentelemetry.io/otel/exporters/metric/prometheus v0.13.0
1718
golang.org/x/net v0.0.0-20200707034311-ab3426394381
19+
golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf // indirect
1820
google.golang.org/grpc v1.27.1
1921
google.golang.org/protobuf v1.25.0
2022
k8s.io/api v0.19.3

go.sum

Lines changed: 191 additions & 26 deletions
Large diffs are not rendered by default.

pkg/metrics/exporter.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import (
1818
"fmt"
1919
"strings"
2020

21-
"go.opentelemetry.io/otel/sdk/metric/controller/push"
22-
2321
"k8s.io/klog/v2"
2422
)
2523

@@ -30,18 +28,14 @@ var (
3028

3129
const prometheusExporter = "prometheus"
3230

33-
func NewMetricsExporter() (m *push.Controller, err error) {
31+
func InitMetricsExporter() error {
3432
mb := strings.ToLower(*metricsBackend)
3533
klog.Infof("metrics backend: %s", mb)
3634
switch mb {
3735
// Prometheus is the only exporter for now
3836
case prometheusExporter:
39-
m, err = newPrometheusExporter()
37+
return initPrometheusExporter()
4038
default:
41-
err = fmt.Errorf("unsupported metrics backend %v", *metricsBackend)
42-
}
43-
if err != nil {
44-
return nil, err
39+
return fmt.Errorf("unsupported metrics backend %v", *metricsBackend)
4540
}
46-
return m, nil
4741
}

pkg/metrics/prometheus_exporter.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,25 @@ import (
1717
"fmt"
1818
"net/http"
1919

20-
"go.opentelemetry.io/otel/api/core"
2120
"go.opentelemetry.io/otel/exporters/metric/prometheus"
22-
"go.opentelemetry.io/otel/sdk/metric/controller/push"
2321
)
2422

25-
func newPrometheusExporter() (*push.Controller, error) {
23+
func initPrometheusExporter() error {
2624
/*
2725
Prometheus exporter for opentelemetry is under active development
28-
Histogram support was added in v0.4.3 - https://github.com/open-telemetry/opentelemetry-go/pull/601
2926
Defining the buckets is due to change in future release - https://github.com/open-telemetry/opentelemetry-go/issues/689
3027
*/
31-
pusher, hf, err := prometheus.InstallNewPipeline(prometheus.Config{
32-
DefaultHistogramBoundaries: []core.Number{
33-
core.NewFloat64Number(0.1),
34-
core.NewFloat64Number(0.2),
35-
core.NewFloat64Number(0.3),
36-
core.NewFloat64Number(0.4),
37-
core.NewFloat64Number(0.5),
38-
core.NewFloat64Number(1),
39-
core.NewFloat64Number(1.5),
40-
core.NewFloat64Number(2),
41-
core.NewFloat64Number(2.5),
42-
core.NewFloat64Number(3.0),
43-
core.NewFloat64Number(5.0),
44-
core.NewFloat64Number(10.0),
45-
core.NewFloat64Number(15.0),
46-
core.NewFloat64Number(30.0),
28+
pusher, err := prometheus.InstallNewPipeline(prometheus.Config{
29+
DefaultHistogramBoundaries: []float64{
30+
0.1, 0.2, 0.3, 0.4, 0.5, 1, 1.5, 2, 2.5, 3.0, 5.0, 10.0, 15.0, 30.0,
4731
}})
4832
if err != nil {
49-
return nil, err
33+
return err
5034
}
51-
http.HandleFunc("/", hf)
35+
http.HandleFunc("/", pusher.ServeHTTP)
5236
go func() {
5337
_ = http.ListenAndServe(fmt.Sprintf(":%v", *prometheusPort), nil)
5438
}()
5539

56-
return pusher, nil
40+
return nil
5741
}

pkg/rotation/stats_reporter.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ import (
1717
"context"
1818
"runtime"
1919

20-
"go.opentelemetry.io/otel/api/core"
2120
"go.opentelemetry.io/otel/api/global"
22-
"go.opentelemetry.io/otel/api/key"
2321
"go.opentelemetry.io/otel/api/metric"
22+
"go.opentelemetry.io/otel/label"
2423
)
2524

2625
var (
@@ -30,7 +29,7 @@ var (
3029
rotatedKey = "rotated"
3130
rotationReconcileTotal metric.Int64Counter
3231
rotationReconcileErrorTotal metric.Int64Counter
33-
rotationReconcileDuration metric.Float64Measure
32+
rotationReconcileDuration metric.Float64ValueRecorder
3433
runtimeOS = runtime.GOOS
3534
)
3635

@@ -48,20 +47,20 @@ func newStatsReporter() StatsReporter {
4847
meter := global.Meter("secretsstore")
4948
rotationReconcileTotal = metric.Must(meter).NewInt64Counter("total_rotation_reconcile", metric.WithDescription("Total number of rotation reconciles"))
5049
rotationReconcileErrorTotal = metric.Must(meter).NewInt64Counter("total_rotation_reconcile_error", metric.WithDescription("Total number of rotation reconciles with error"))
51-
rotationReconcileDuration = metric.Must(meter).NewFloat64Measure("rotation_reconcile_duration_sec", metric.WithDescription("Distribution of how long it took to rotate secrets-store content for pods"))
50+
rotationReconcileDuration = metric.Must(meter).NewFloat64ValueRecorder("rotation_reconcile_duration_sec", metric.WithDescription("Distribution of how long it took to rotate secrets-store content for pods"))
5251
return &reporter{meter: meter}
5352
}
5453

5554
func (r *reporter) reportRotationCtMetric(provider string, wasRotated bool) {
56-
labels := []core.KeyValue{key.String(providerKey, provider), key.String(osTypeKey, runtimeOS), key.Bool(rotatedKey, wasRotated)}
55+
labels := []label.KeyValue{label.String(providerKey, provider), label.String(osTypeKey, runtimeOS), label.Bool(rotatedKey, wasRotated)}
5756
rotationReconcileTotal.Add(context.Background(), 1, labels...)
5857
}
5958

6059
func (r *reporter) reportRotationErrorCtMetric(provider, errType string, wasRotated bool) {
61-
labels := []core.KeyValue{key.String(providerKey, provider), key.String(errorKey, errType), key.String(osTypeKey, runtimeOS), key.Bool(rotatedKey, wasRotated)}
60+
labels := []label.KeyValue{label.String(providerKey, provider), label.String(errorKey, errType), label.String(osTypeKey, runtimeOS), label.Bool(rotatedKey, wasRotated)}
6261
rotationReconcileErrorTotal.Add(context.Background(), 1, labels...)
6362
}
6463

6564
func (r *reporter) reportRotationDuration(duration float64) {
66-
r.meter.RecordBatch(context.Background(), []core.KeyValue{key.String(osTypeKey, runtimeOS)}, rotationReconcileDuration.Measurement(duration))
65+
r.meter.RecordBatch(context.Background(), []label.KeyValue{label.String(osTypeKey, runtimeOS)}, rotationReconcileDuration.Measurement(duration))
6766
}

pkg/secrets-store/stats_reporter.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ import (
1717
"context"
1818
"runtime"
1919

20-
"go.opentelemetry.io/otel/api/core"
2120
"go.opentelemetry.io/otel/api/global"
22-
"go.opentelemetry.io/otel/api/key"
2321
"go.opentelemetry.io/otel/api/metric"
22+
"go.opentelemetry.io/otel/label"
2423
)
2524

2625
var (
@@ -32,7 +31,7 @@ var (
3231
nodePublishErrorTotal metric.Int64Counter
3332
nodeUnPublishErrorTotal metric.Int64Counter
3433
syncK8sSecretTotal metric.Int64Counter
35-
syncK8sSecretDuration metric.Float64Measure
34+
syncK8sSecretDuration metric.Float64ValueRecorder
3635
runtimeOS = runtime.GOOS
3736
)
3837

@@ -56,33 +55,33 @@ func NewStatsReporter() StatsReporter {
5655
nodePublishErrorTotal = metric.Must(meter).NewInt64Counter("total_node_publish_error", metric.WithDescription("Total number of node publish calls with error"))
5756
nodeUnPublishErrorTotal = metric.Must(meter).NewInt64Counter("total_node_unpublish_error", metric.WithDescription("Total number of node unpublish calls with error"))
5857
syncK8sSecretTotal = metric.Must(meter).NewInt64Counter("total_sync_k8s_secret", metric.WithDescription("Total number of k8s secrets synced"))
59-
syncK8sSecretDuration = metric.Must(meter).NewFloat64Measure("sync_k8s_secret_duration_sec", metric.WithDescription("Distribution of how long it took to sync k8s secret"))
58+
syncK8sSecretDuration = metric.Must(meter).NewFloat64ValueRecorder("sync_k8s_secret_duration_sec", metric.WithDescription("Distribution of how long it took to sync k8s secret"))
6059
return &reporter{meter: meter}
6160
}
6261

6362
func (r *reporter) ReportNodePublishCtMetric(provider string) {
64-
labels := []core.KeyValue{key.String(providerKey, provider), key.String(osTypeKey, runtimeOS)}
63+
labels := []label.KeyValue{label.String(providerKey, provider), label.String(osTypeKey, runtimeOS)}
6564
nodePublishTotal.Add(context.Background(), 1, labels...)
6665
}
6766

6867
func (r *reporter) ReportNodeUnPublishCtMetric() {
69-
nodeUnPublishTotal.Add(context.Background(), 1, []core.KeyValue{key.String(osTypeKey, runtimeOS)}...)
68+
nodeUnPublishTotal.Add(context.Background(), 1, []label.KeyValue{label.String(osTypeKey, runtimeOS)}...)
7069
}
7170

7271
func (r *reporter) ReportNodePublishErrorCtMetric(provider, errType string) {
73-
labels := []core.KeyValue{key.String(providerKey, provider), key.String(errorKey, errType), key.String(osTypeKey, runtimeOS)}
72+
labels := []label.KeyValue{label.String(providerKey, provider), label.String(errorKey, errType), label.String(osTypeKey, runtimeOS)}
7473
nodePublishErrorTotal.Add(context.Background(), 1, labels...)
7574
}
7675

7776
func (r *reporter) ReportNodeUnPublishErrorCtMetric() {
78-
nodeUnPublishErrorTotal.Add(context.Background(), 1, []core.KeyValue{key.String(osTypeKey, runtimeOS)}...)
77+
nodeUnPublishErrorTotal.Add(context.Background(), 1, []label.KeyValue{label.String(osTypeKey, runtimeOS)}...)
7978
}
8079

8180
func (r *reporter) ReportSyncK8SecretCtMetric(provider string, count int) {
82-
labels := []core.KeyValue{key.String(providerKey, provider), key.String(osTypeKey, runtimeOS)}
81+
labels := []label.KeyValue{label.String(providerKey, provider), label.String(osTypeKey, runtimeOS)}
8382
syncK8sSecretTotal.Add(context.Background(), int64(count), labels...)
8483
}
8584

8685
func (r *reporter) ReportSyncK8SecretDuration(duration float64) {
87-
r.meter.RecordBatch(context.Background(), []core.KeyValue{key.String(osTypeKey, runtimeOS)}, syncK8sSecretDuration.Measurement(duration))
86+
r.meter.RecordBatch(context.Background(), []label.KeyValue{label.String(osTypeKey, runtimeOS)}, syncK8sSecretDuration.Measurement(duration))
8887
}

0 commit comments

Comments
 (0)