@@ -94,11 +94,6 @@ func exportMetrics(ctx context.Context, filename string, meter skaffoldMeter) er
94
94
}
95
95
var meters []skaffoldMeter
96
96
err = json .Unmarshal (b , & meters )
97
- // each meter contains around 20 datapoints, and each datapoint requires a request to firelog api
98
- // we send at most 10 meters stored in skaffold metrics as too many request may result in the firelog server returning 429.
99
- if len (meters ) >= 10 {
100
- meters = meters [:10 ]
101
- }
102
97
if err != nil {
103
98
meters = []skaffoldMeter {}
104
99
}
@@ -165,13 +160,17 @@ func devStdOutExporter() (sdkmetric.Exporter, error) {
165
160
}
166
161
167
162
func createMetrics (ctx context.Context , meter skaffoldMeter ) {
168
- m := global .Meter ("skaffold" )
169
-
163
+ // There is a minimum 10 second interval that metrics are allowed to upload to Cloud monitoring
170
164
// A metric is uniquely identified by the metric name and the labels and corresponding values
171
165
// This random number is used as a label to differentiate the metrics per user so if two users
172
166
// run `skaffold build` at the same time they will both have their metrics recorded
173
167
randLabel := attribute .String ("randomizer" , strconv .Itoa (rand .Intn (75000 )))
174
168
169
+ m := global .Meter ("skaffold" )
170
+
171
+ // cloud monitoring only supports string type labels
172
+ // cloud monitoring only supports 10 labels per metric descriptor
173
+ // be careful when appending new values to this `labels` slice
175
174
labels := []attribute.KeyValue {
176
175
attribute .String ("version" , meter .Version ),
177
176
attribute .String ("os" , meter .OS ),
@@ -181,13 +180,15 @@ func createMetrics(ctx context.Context, meter skaffoldMeter) {
181
180
attribute .String ("platform_type" , meter .PlatformType ),
182
181
attribute .String ("config_count" , strconv .Itoa (meter .ConfigCount )),
183
182
attribute .String ("cluster_type" , meter .ClusterType ),
184
- attribute .String ("ci_cd_platform" , meter .CISystem ),
183
+ }
184
+ sharedLabels := []attribute.KeyValue {
185
185
randLabel ,
186
186
}
187
187
188
188
if allowedUser := user .IsAllowedUser (meter .User ); allowedUser {
189
- labels = append (labels , attribute .String ("user" , meter .User ))
189
+ sharedLabels = append (sharedLabels , attribute .String ("user" , meter .User ))
190
190
}
191
+ labels = append (labels , sharedLabels ... )
191
192
platformLabel := attribute .String ("host_os_arch" , fmt .Sprintf ("%s/%s" , meter .OS , meter .Arch ))
192
193
runCounter := NewInt64ValueRecorder (m , "launches" , instrument .WithDescription ("Skaffold Invocations" ))
193
194
runCounter .Record (ctx , 1 , labels ... )
@@ -196,36 +197,36 @@ func createMetrics(ctx context.Context, meter skaffoldMeter) {
196
197
instrument .WithDescription ("durations of skaffold commands in seconds" ))
197
198
durationRecorder .Record (ctx , meter .Duration .Seconds (), labels ... )
198
199
if meter .Command != "" {
199
- commandMetrics (ctx , meter , m , labels ... )
200
- flagMetrics (ctx , meter , m , labels ... )
200
+ commandMetrics (ctx , meter , m , sharedLabels ... )
201
+ flagMetrics (ctx , meter , m , randLabel )
201
202
hooksMetrics (ctx , meter , m , labels ... )
202
203
if doesBuild .Contains (meter .Command ) {
203
- builderMetrics (ctx , meter , m , platformLabel , labels ... )
204
+ builderMetrics (ctx , meter , m , platformLabel , sharedLabels ... )
204
205
}
205
206
if doesDeploy .Contains (meter .Command ) {
206
- deployerMetrics (ctx , meter , m , labels ... )
207
+ deployerMetrics (ctx , meter , m , sharedLabels ... )
207
208
}
208
209
if doesDeploy .Contains (meter .Command ) || meter .Command == "render" {
209
- resourceSelectorMetrics (ctx , meter , m , labels ... )
210
+ resourceSelectorMetrics (ctx , meter , m , sharedLabels ... )
210
211
}
211
212
}
212
213
213
214
if meter .ErrorCode != 0 {
214
- errorMetrics (ctx , meter , m , append (labels , platformLabel )... )
215
+ errorMetrics (ctx , meter , m , append (sharedLabels , platformLabel )... )
215
216
}
216
217
}
217
218
218
- func flagMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , labels ... attribute.KeyValue ) {
219
+ func flagMetrics (ctx context.Context , meter skaffoldMeter , m metric.Meter , randLabel attribute.KeyValue ) {
219
220
flagCounter := NewInt64ValueRecorder (m , "flags" , instrument .WithDescription ("Tracks usage of enum flags" ))
220
221
for k , v := range meter .EnumFlags {
221
- l := []attribute.KeyValue {
222
+ labels := []attribute.KeyValue {
222
223
attribute .String ("flag_name" , k ),
223
224
attribute .String ("flag_value" , v ),
224
225
attribute .String ("command" , meter .Command ),
225
226
attribute .String ("error" , meter .ErrorCode .String ()),
227
+ randLabel ,
226
228
}
227
- l = append (l , labels ... )
228
- flagCounter .Record (ctx , 1 , l ... )
229
+ flagCounter .Record (ctx , 1 , labels ... )
229
230
}
230
231
}
231
232
@@ -248,13 +249,12 @@ func commandMetrics(ctx context.Context, meter skaffoldMeter, m metric.Meter, la
248
249
m := counts [iteration .Intent ]
249
250
m [iteration .ErrorCode ]++
250
251
}
251
- randomizer := attribute .String ("randomizer2" , strconv .Itoa (rand .Intn (75000 )))
252
252
for intention , errorCounts := range counts {
253
253
for errorCode , count := range errorCounts {
254
254
iterationCounter .Record (ctx , int64 (count ),
255
255
append (labels ,
256
256
attribute .String ("intent" , intention ),
257
- attribute .String ("error" , errorCode .String ()), randomizer ,
257
+ attribute .String ("error" , errorCode .String ()),
258
258
)... )
259
259
}
260
260
}
0 commit comments