@@ -42,7 +42,7 @@ import (
42
42
43
43
"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/statik"
44
44
45
- // import embedded secret for uploading metrics
45
+ // import embedded secret for uploading metrics
46
46
_ "github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/secret/statik"
47
47
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
48
48
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
@@ -61,7 +61,7 @@ type skaffoldMeter struct {
61
61
Arch string
62
62
PlatformType string
63
63
Deployers []string
64
- EnumFlags map [string ]* flag. Flag
64
+ EnumFlags map [string ]string
65
65
Builders map [string ]int
66
66
SyncType map [string ]bool
67
67
DevIterations []devIteration
@@ -71,15 +71,15 @@ type skaffoldMeter struct {
71
71
}
72
72
73
73
type devIteration struct {
74
- intent string
75
- errorCode proto.StatusCode
74
+ Intent string
75
+ ErrorCode proto.StatusCode
76
76
}
77
77
78
78
var (
79
79
meter = skaffoldMeter {
80
80
OS : runtime .GOOS ,
81
81
Arch : runtime .GOARCH ,
82
- EnumFlags : map [string ]* flag. Flag {},
82
+ EnumFlags : map [string ]string {},
83
83
Builders : map [string ]int {},
84
84
SyncType : map [string ]bool {},
85
85
DevIterations : []devIteration {},
92
92
meteredCommands = util .NewStringSet ()
93
93
doesBuild = util .NewStringSet ()
94
94
doesDeploy = util .NewStringSet ()
95
+ initExporter = initCloudMonitoringExporterMetrics
95
96
isOnline bool
96
97
)
97
98
@@ -113,11 +114,7 @@ func init() {
113
114
func InitMeterFromConfig (config * latest.SkaffoldConfig ) {
114
115
meter .PlatformType = yamltags .GetYamlTag (config .Build .BuildType )
115
116
for _ , artifact := range config .Pipeline .Build .Artifacts {
116
- if _ , ok := meter .Builders [yamltags .GetYamlTag (artifact .ArtifactType )]; ok {
117
- meter .Builders [yamltags .GetYamlTag (artifact .ArtifactType )]++
118
- } else {
119
- meter .Builders [yamltags .GetYamlTag (artifact .ArtifactType )] = 1
120
- }
117
+ meter .Builders [yamltags .GetYamlTag (artifact .ArtifactType )]++
121
118
if artifact .Sync != nil {
122
119
meter .SyncType [yamltags .GetYamlTag (artifact .Sync )] = true
123
120
}
@@ -137,18 +134,20 @@ func SetErrorCode(errorCode proto.StatusCode) {
137
134
}
138
135
139
136
func AddDevIteration (intent string ) {
140
- meter .DevIterations = append (meter .DevIterations , devIteration {intent : intent })
137
+ meter .DevIterations = append (meter .DevIterations , devIteration {Intent : intent })
141
138
}
142
139
143
140
func AddDevIterationErr (i int , errorCode proto.StatusCode ) {
144
141
if len (meter .DevIterations ) == i {
145
- meter .DevIterations = append (meter .DevIterations , devIteration {intent : "error" })
142
+ meter .DevIterations = append (meter .DevIterations , devIteration {Intent : "error" })
146
143
}
147
- meter .DevIterations [i ].errorCode = errorCode
144
+ meter .DevIterations [i ].ErrorCode = errorCode
148
145
}
149
146
150
147
func AddFlag (flag * flag.Flag ) {
151
- meter .EnumFlags [flag .Name ] = flag
148
+ if flag .Changed {
149
+ meter .EnumFlags [flag .Name ] = flag .Value .String ()
150
+ }
152
151
}
153
152
154
153
func ExportMetrics (exitCode int ) error {
@@ -168,7 +167,7 @@ func ExportMetrics(exitCode int) error {
168
167
169
168
func exportMetrics (ctx context.Context , filename string , meter skaffoldMeter ) error {
170
169
logrus .Debug ("exporting metrics" )
171
- p , err := initCloudMonitoringExporterMetrics ()
170
+ p , err := initExporter ()
172
171
if p == nil {
173
172
return err
174
173
}
@@ -189,11 +188,13 @@ func exportMetrics(ctx context.Context, filename string, meter skaffoldMeter) er
189
188
return ioutil .WriteFile (filename , b , 0666 )
190
189
}
191
190
191
+ start := time .Now ()
192
192
p .Start ()
193
193
for _ , m := range meters {
194
194
createMetrics (ctx , m )
195
195
}
196
196
p .Stop ()
197
+ logrus .Debugf ("metrics uploading complete in %s" , time .Since (start ).String ())
197
198
198
199
if fileExists {
199
200
return os .Remove (filename )
@@ -221,8 +222,8 @@ func initCloudMonitoringExporterMetrics() (*push.Controller, error) {
221
222
222
223
var c creds
223
224
err = json .Unmarshal (b , & c )
224
- if err != nil {
225
- return nil , fmt .Errorf ("error unmarsharling metrics credentials: %v" , err )
225
+ if c . ProjectID == "" || err != nil {
226
+ return nil , fmt .Errorf ("no project id found in metrics credentials" )
226
227
}
227
228
228
229
formatter := func (desc * metric.Descriptor ) string {
@@ -295,14 +296,11 @@ func commandMetrics(ctx context.Context, meter skaffoldMeter, m metric.Meter, ra
295
296
counts := make (map [string ]map [proto.StatusCode ]int )
296
297
297
298
for _ , iteration := range meter .DevIterations {
298
- if _ , ok := counts [iteration .intent ]; ! ok {
299
- counts [iteration .intent ] = make (map [proto.StatusCode ]int )
300
- }
301
- m := counts [iteration .intent ]
302
- if _ , ok := m [iteration .errorCode ]; ! ok {
303
- m [iteration .errorCode ] = 0
299
+ if _ , ok := counts [iteration .Intent ]; ! ok {
300
+ counts [iteration .Intent ] = make (map [proto.StatusCode ]int )
304
301
}
305
- m [iteration .errorCode ]++
302
+ m := counts [iteration .Intent ]
303
+ m [iteration .ErrorCode ]++
306
304
}
307
305
for intention , errorCounts := range counts {
308
306
for errorCode , count := range errorCounts {
0 commit comments