@@ -3,7 +3,6 @@ package phases
3
3
import (
4
4
"context"
5
5
"errors"
6
- "slices"
7
6
8
7
"github.com/databricks/cli/bundle"
9
8
"github.com/databricks/cli/bundle/apps"
@@ -21,11 +20,8 @@ import (
21
20
"github.com/databricks/cli/bundle/trampoline"
22
21
"github.com/databricks/cli/libs/cmdio"
23
22
"github.com/databricks/cli/libs/diag"
24
- "github.com/databricks/cli/libs/dyn"
25
23
"github.com/databricks/cli/libs/log"
26
24
"github.com/databricks/cli/libs/sync"
27
- "github.com/databricks/cli/libs/telemetry"
28
- "github.com/databricks/cli/libs/telemetry/protos"
29
25
terraformlib "github.com/databricks/cli/libs/terraform"
30
26
tfjson "github.com/hashicorp/terraform-json"
31
27
)
@@ -233,7 +229,7 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
233
229
return diags
234
230
}
235
231
236
- logTelemetry (ctx , b )
232
+ logDeployTelemetry (ctx , b )
237
233
return diags .Extend (bundle .Apply (ctx , b , scripts .Execute (config .ScriptPostDeploy )))
238
234
}
239
235
@@ -242,156 +238,3 @@ func Deploy(ctx context.Context, b *bundle.Bundle, outputHandler sync.OutputHand
242
238
// Since we have a timeout of 3 seconds, we cap the maximum number of IDs
243
239
// we send in a single request to have reliable telemetry.
244
240
const ResourceIdLimit = 1000
245
-
246
- func logTelemetry (ctx context.Context , b * bundle.Bundle ) {
247
- resourcesCount := int64 (0 )
248
- _ , err := dyn .MapByPattern (b .Config .Value (), dyn .NewPattern (dyn .Key ("resources" ), dyn .AnyKey (), dyn .AnyKey ()), func (p dyn.Path , v dyn.Value ) (dyn.Value , error ) {
249
- resourcesCount ++
250
- return v , nil
251
- })
252
- if err != nil {
253
- log .Debugf (ctx , "failed to count resources: %s" , err )
254
- }
255
-
256
- var jobsIds []string
257
- for _ , job := range b .Config .Resources .Jobs {
258
- if len (jobsIds ) >= ResourceIdLimit {
259
- break
260
- }
261
-
262
- // Do not include missing IDs in telemetry. We can still detect them
263
- // by comparing against the resource count.
264
- if job == nil || job .ID == "" {
265
- continue
266
- }
267
- jobsIds = append (jobsIds , job .ID )
268
- }
269
- var pipelineIds []string
270
- for _ , pipeline := range b .Config .Resources .Pipelines {
271
- if len (pipelineIds ) >= ResourceIdLimit {
272
- break
273
- }
274
-
275
- // Do not include missing IDs in telemetry. We can still detect them
276
- // by comparing against the resource count.
277
- if pipeline == nil || pipeline .ID == "" {
278
- continue
279
- }
280
- pipelineIds = append (pipelineIds , pipeline .ID )
281
- }
282
- var clusterIds []string
283
- for _ , cluster := range b .Config .Resources .Clusters {
284
- if len (clusterIds ) >= ResourceIdLimit {
285
- break
286
- }
287
-
288
- // Do not include missing IDs in telemetry. We can still detect them
289
- // by comparing against the resource count.
290
- if cluster == nil || cluster .ID == "" {
291
- continue
292
- }
293
- clusterIds = append (clusterIds , cluster .ID )
294
- }
295
- var dashboardIds []string
296
- for _ , dashboard := range b .Config .Resources .Dashboards {
297
- if len (dashboardIds ) >= ResourceIdLimit {
298
- break
299
- }
300
-
301
- // Do not include missing IDs in telemetry. We can still detect them
302
- // by comparing against the resource count.
303
- if dashboard == nil || dashboard .ID == "" {
304
- continue
305
- }
306
- dashboardIds = append (dashboardIds , dashboard .ID )
307
- }
308
-
309
- // sort the IDs to make the record generated deterministic
310
- // this is important for testing purposes
311
- slices .Sort (jobsIds )
312
- slices .Sort (pipelineIds )
313
- slices .Sort (clusterIds )
314
- slices .Sort (dashboardIds )
315
-
316
- // If the bundle UUID is not set, we use a default 0 value.
317
- bundleUuid := "00000000-0000-0000-0000-000000000000"
318
- if b .Config .Bundle .Uuid != "" {
319
- bundleUuid = b .Config .Bundle .Uuid
320
- }
321
-
322
- variableCount := len (b .Config .Variables )
323
- complexVariableCount := int64 (0 )
324
- lookupVariableCount := int64 (0 )
325
- for _ , v := range b .Config .Variables {
326
- // If the resolved value of the variable is a complex type, we count it as a complex variable.
327
- // We can't rely on the "type: complex" annotation because the annotation is optional in some contexts
328
- // like bundle YAML files.
329
- if v .IsComplexValued () {
330
- complexVariableCount ++
331
- }
332
-
333
- if v .Lookup != nil {
334
- lookupVariableCount ++
335
- }
336
- }
337
-
338
- artifactPathType := protos .BundleDeployArtifactPathTypeUnspecified
339
- if libraries .IsVolumesPath (b .Config .Workspace .ArtifactPath ) {
340
- artifactPathType = protos .BundleDeployArtifactPathTypeVolume
341
- } else if libraries .IsWorkspacePath (b .Config .Workspace .ArtifactPath ) {
342
- artifactPathType = protos .BundleDeployArtifactPathTypeWorkspace
343
- }
344
-
345
- mode := protos .BundleModeUnspecified
346
- if b .Config .Bundle .Mode == config .Development {
347
- mode = protos .BundleModeDevelopment
348
- } else if b .Config .Bundle .Mode == config .Production {
349
- mode = protos .BundleModeProduction
350
- }
351
-
352
- experimentalConfig := b .Config .Experimental
353
- if experimentalConfig == nil {
354
- experimentalConfig = & config.Experimental {}
355
- }
356
-
357
- telemetry .Log (ctx , protos.DatabricksCliLog {
358
- BundleDeployEvent : & protos.BundleDeployEvent {
359
- BundleUuid : bundleUuid ,
360
- DeploymentId : b .Metrics .DeploymentId .String (),
361
-
362
- ResourceCount : resourcesCount ,
363
- ResourceJobCount : int64 (len (b .Config .Resources .Jobs )),
364
- ResourcePipelineCount : int64 (len (b .Config .Resources .Pipelines )),
365
- ResourceModelCount : int64 (len (b .Config .Resources .Models )),
366
- ResourceExperimentCount : int64 (len (b .Config .Resources .Experiments )),
367
- ResourceModelServingEndpointCount : int64 (len (b .Config .Resources .ModelServingEndpoints )),
368
- ResourceRegisteredModelCount : int64 (len (b .Config .Resources .RegisteredModels )),
369
- ResourceQualityMonitorCount : int64 (len (b .Config .Resources .QualityMonitors )),
370
- ResourceSchemaCount : int64 (len (b .Config .Resources .Schemas )),
371
- ResourceVolumeCount : int64 (len (b .Config .Resources .Volumes )),
372
- ResourceClusterCount : int64 (len (b .Config .Resources .Clusters )),
373
- ResourceDashboardCount : int64 (len (b .Config .Resources .Dashboards )),
374
- ResourceAppCount : int64 (len (b .Config .Resources .Apps )),
375
-
376
- ResourceJobIDs : jobsIds ,
377
- ResourcePipelineIDs : pipelineIds ,
378
- ResourceClusterIDs : clusterIds ,
379
- ResourceDashboardIDs : dashboardIds ,
380
-
381
- Experimental : & protos.BundleDeployExperimental {
382
- BundleMode : mode ,
383
- ConfigurationFileCount : b .Metrics .ConfigurationFileCount ,
384
- TargetCount : b .Metrics .TargetCount ,
385
- WorkspaceArtifactPathType : artifactPathType ,
386
- BoolValues : b .Metrics .BoolValues ,
387
- PythonAddedResourcesCount : b .Metrics .PythonAddedResourcesCount ,
388
- PythonUpdatedResourcesCount : b .Metrics .PythonUpdatedResourcesCount ,
389
- PythonResourceLoadersCount : int64 (len (experimentalConfig .Python .Resources )),
390
- PythonResourceMutatorsCount : int64 (len (experimentalConfig .Python .Mutators )),
391
- VariableCount : int64 (variableCount ),
392
- ComplexVariableCount : complexVariableCount ,
393
- LookupVariableCount : lookupVariableCount ,
394
- },
395
- },
396
- })
397
- }
0 commit comments