@@ -31,11 +31,12 @@ import (
31
31
"github.com/mitchellh/go-homedir"
32
32
"github.com/rakyll/statik/fs"
33
33
"github.com/sirupsen/logrus"
34
- "go.opentelemetry.io/otel/api/global "
35
- "go.opentelemetry.io/otel/api/metric "
34
+ "go.opentelemetry.io/otel"
35
+ "go.opentelemetry.io/otel/attribute "
36
36
"go.opentelemetry.io/otel/exporters/stdout"
37
- "go.opentelemetry.io/otel/label"
38
- "go.opentelemetry.io/otel/sdk/metric/controller/push"
37
+ "go.opentelemetry.io/otel/metric"
38
+ "go.opentelemetry.io/otel/metric/global"
39
+ "go.opentelemetry.io/otel/sdk/metric/controller/basic"
39
40
"google.golang.org/api/option"
40
41
41
42
"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/statik"
@@ -90,11 +91,11 @@ func exportMetrics(ctx context.Context, filename string, meter skaffoldMeter) er
90
91
}
91
92
92
93
start := time .Now ()
93
- p .Start ()
94
+ p .Start (ctx )
94
95
for _ , m := range meters {
95
96
createMetrics (ctx , m )
96
97
}
97
- p .Stop ()
98
+ p .Stop (ctx )
98
99
logrus .Debugf ("metrics uploading complete in %s" , time .Since (start ).String ())
99
100
100
101
if fileExists {
@@ -103,7 +104,7 @@ func exportMetrics(ctx context.Context, filename string, meter skaffoldMeter) er
103
104
return nil
104
105
}
105
106
106
- func initCloudMonitoringExporterMetrics () (* push .Controller , error ) {
107
+ func initCloudMonitoringExporterMetrics () (* basic .Controller , error ) {
107
108
statikFS , err := statik .FS ()
108
109
if err != nil {
109
110
return nil , err
@@ -127,7 +128,7 @@ func initCloudMonitoringExporterMetrics() (*push.Controller, error) {
127
128
return fmt .Sprintf ("custom.googleapis.com/skaffold/%s" , desc .Name ())
128
129
}
129
130
130
- global .SetErrorHandler (errHandler {})
131
+ otel .SetErrorHandler (errHandler {})
131
132
return mexporter .InstallNewPipeline (
132
133
[]mexporter.Option {
133
134
mexporter .WithProjectID (c .ProjectID ),
@@ -140,14 +141,14 @@ func initCloudMonitoringExporterMetrics() (*push.Controller, error) {
140
141
)
141
142
}
142
143
143
- func devStdOutExporter () (* push .Controller , error ) {
144
+ func devStdOutExporter () (* basic .Controller , error ) {
144
145
// export metrics to std out if local env is set.
145
146
if _ , ok := os .LookupEnv ("SKAFFOLD_EXPORT_TO_STDOUT" ); ok {
146
- return stdout .InstallNewPipeline ([]stdout.Option {
147
- stdout .WithQuantiles ([]float64 {0.5 }),
147
+ _ , controller , err := stdout .InstallNewPipeline ([]stdout.Option {
148
148
stdout .WithPrettyPrint (),
149
149
stdout .WithWriter (os .Stdout ),
150
150
}, nil )
151
+ return controller , err
151
152
}
152
153
return nil , nil
153
154
}
@@ -157,25 +158,25 @@ func createMetrics(ctx context.Context, meter skaffoldMeter) {
157
158
// A metric is uniquely identified by the metric name and the labels and corresponding values
158
159
// This random number is used as a label to differentiate the metrics per user so if two users
159
160
// run `skaffold build` at the same time they will both have their metrics recorded
160
- randLabel := label .String ("randomizer" , strconv .Itoa (rand .Intn (75000 )))
161
+ randLabel := attribute .String ("randomizer" , strconv .Itoa (rand .Intn (75000 )))
161
162
162
163
m := global .Meter ("skaffold" )
163
164
164
165
// cloud monitoring only supports string type labels
165
- labels := []label .KeyValue {
166
- label .String ("version" , meter .Version ),
167
- label .String ("os" , meter .OS ),
168
- label .String ("arch" , meter .Arch ),
169
- label .String ("command" , meter .Command ),
170
- label .String ("error" , meter .ErrorCode .String ()),
171
- label .String ("platform_type" , meter .PlatformType ),
172
- label .String ("config_count" , strconv .Itoa (meter .ConfigCount )),
166
+ labels := []attribute .KeyValue {
167
+ attribute .String ("version" , meter .Version ),
168
+ attribute .String ("os" , meter .OS ),
169
+ attribute .String ("arch" , meter .Arch ),
170
+ attribute .String ("command" , meter .Command ),
171
+ attribute .String ("error" , meter .ErrorCode .String ()),
172
+ attribute .String ("platform_type" , meter .PlatformType ),
173
+ attribute .String ("config_count" , strconv .Itoa (meter .ConfigCount )),
173
174
}
174
- sharedLabels := []label .KeyValue {
175
+ sharedLabels := []attribute .KeyValue {
175
176
randLabel ,
176
177
}
177
178
if _ , ok := allowedUsers [meter .User ]; ok {
178
- sharedLabels = append (sharedLabels , label .String ("user" , meter .User ))
179
+ sharedLabels = append (sharedLabels , attribute .String ("user" , meter .User ))
179
180
}
180
181
labels = append (labels , sharedLabels ... )
181
182
@@ -201,24 +202,24 @@ func createMetrics(ctx context.Context, meter skaffoldMeter) {
201
202
}
202
203
}
203
204
204
- func flagMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , randLabel label .KeyValue ) {
205
+ func flagMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , randLabel attribute .KeyValue ) {
205
206
flagCounter := metric .Must (m ).NewInt64ValueRecorder ("flags" , metric .WithDescription ("Tracks usage of enum flags" ))
206
207
for k , v := range meter .EnumFlags {
207
- labels := []label .KeyValue {
208
- label .String ("flag_name" , k ),
209
- label .String ("flag_value" , v ),
210
- label .String ("command" , meter .Command ),
211
- label .String ("error" , meter .ErrorCode .String ()),
208
+ labels := []attribute .KeyValue {
209
+ attribute .String ("flag_name" , k ),
210
+ attribute .String ("flag_value" , v ),
211
+ attribute .String ("command" , meter .Command ),
212
+ attribute .String ("error" , meter .ErrorCode .String ()),
212
213
randLabel ,
213
214
}
214
215
flagCounter .Record (ctx , 1 , labels ... )
215
216
}
216
217
}
217
218
218
- func commandMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , labels ... label .KeyValue ) {
219
+ func commandMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , labels ... attribute .KeyValue ) {
219
220
commandCounter := metric .Must (m ).NewInt64ValueRecorder (meter .Command ,
220
221
metric .WithDescription (fmt .Sprintf ("Number of times %s is used" , meter .Command )))
221
- labels = append (labels , label .String ("error" , meter .ErrorCode .String ()))
222
+ labels = append (labels , attribute .String ("error" , meter .ErrorCode .String ()))
222
223
commandCounter .Record (ctx , 1 , labels ... )
223
224
224
225
if meter .Command == "dev" || meter .Command == "debug" {
@@ -238,42 +239,42 @@ func commandMetrics(ctx context.Context, meter skaffoldMeter, m metric.Meter, la
238
239
for errorCode , count := range errorCounts {
239
240
iterationCounter .Record (ctx , int64 (count ),
240
241
append (labels ,
241
- label .String ("intent" , intention ),
242
- label .String ("error" , errorCode .String ()),
242
+ attribute .String ("intent" , intention ),
243
+ attribute .String ("error" , errorCode .String ()),
243
244
)... )
244
245
}
245
246
}
246
247
}
247
248
}
248
249
249
- func deployerMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , labels ... label .KeyValue ) {
250
+ func deployerMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , labels ... attribute .KeyValue ) {
250
251
deployerCounter := metric .Must (m ).NewInt64ValueRecorder ("deployer" , metric .WithDescription ("Deployers used" ))
251
252
for _ , deployer := range meter .Deployers {
252
- deployerCounter .Record (ctx , 1 , append (labels , label .String ("deployer" , deployer ))... )
253
+ deployerCounter .Record (ctx , 1 , append (labels , attribute .String ("deployer" , deployer ))... )
253
254
}
254
255
if meter .HelmReleasesCount > 0 {
255
256
multiReleasesCounter := metric .Must (m ).NewInt64ValueRecorder ("helmReleases" , metric .WithDescription ("Multiple helm releases used" ))
256
- multiReleasesCounter .Record (ctx , 1 , append (labels , label .Int ("count" , meter .HelmReleasesCount ))... )
257
+ multiReleasesCounter .Record (ctx , 1 , append (labels , attribute .Int ("count" , meter .HelmReleasesCount ))... )
257
258
}
258
259
}
259
260
260
- func builderMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , labels ... label .KeyValue ) {
261
+ func builderMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , labels ... attribute .KeyValue ) {
261
262
builderCounter := metric .Must (m ).NewInt64ValueRecorder ("builders" , metric .WithDescription ("Builders used" ))
262
263
artifactCounter := metric .Must (m ).NewInt64ValueRecorder ("artifacts" , metric .WithDescription ("Number of artifacts used" ))
263
264
dependenciesCounter := metric .Must (m ).NewInt64ValueRecorder ("artifact-dependencies" , metric .WithDescription ("Number of artifacts with dependencies" ))
264
265
for builder , count := range meter .Builders {
265
- bLabel := label .String ("builder" , builder )
266
+ bLabel := attribute .String ("builder" , builder )
266
267
builderCounter .Record (ctx , 1 , append (labels , bLabel )... )
267
268
artifactCounter .Record (ctx , int64 (count ), append (labels , bLabel )... )
268
269
dependenciesCounter .Record (ctx , int64 (meter .BuildDependencies [builder ]), append (labels , bLabel )... )
269
270
}
270
271
}
271
272
272
- func errorMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , labels ... label .KeyValue ) {
273
+ func errorMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , labels ... attribute .KeyValue ) {
273
274
errCounter := metric .Must (m ).NewInt64ValueRecorder ("errors" , metric .WithDescription ("Skaffold errors" ))
274
- errCounter .Record (ctx , 1 , append (labels , label .String ("error" , meter .ErrorCode .String ()))... )
275
+ errCounter .Record (ctx , 1 , append (labels , attribute .String ("error" , meter .ErrorCode .String ()))... )
275
276
276
- labels = append (labels , label .String ("command" , meter .Command ))
277
+ labels = append (labels , attribute .String ("command" , meter .Command ))
277
278
278
279
switch meter .ErrorCode {
279
280
case proto .StatusCode_UNKNOWN_ERROR :
0 commit comments