diff --git a/integration/libs/telemetry/telemetry_test.go b/integration/libs/telemetry/telemetry_test.go index 830b1f0cc..9632d46b6 100644 --- a/integration/libs/telemetry/telemetry_test.go +++ b/integration/libs/telemetry/telemetry_test.go @@ -8,6 +8,7 @@ import ( "github.com/databricks/cli/integration/internal/acc" "github.com/databricks/cli/libs/telemetry" + "github.com/databricks/cli/libs/telemetry/events" "github.com/databricks/databricks-sdk-go/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -42,16 +43,16 @@ func TestTelemetryLogger(t *testing.T) { // Log some events. err := telemetry.Log(ctx, telemetry.FrontendLogEntry{ DatabricksCliLog: telemetry.DatabricksCliLog{ - CliTestEvent: telemetry.CliTestEvent{ - Name: telemetry.DummyCliEnumValue1, + CliTestEvent: events.CliTestEvent{ + Name: events.DummyCliEnumValue1, }, }, }) require.NoError(t, err) err = telemetry.Log(ctx, telemetry.FrontendLogEntry{ DatabricksCliLog: telemetry.DatabricksCliLog{ - CliTestEvent: telemetry.CliTestEvent{ - Name: telemetry.DummyCliEnumValue2, + CliTestEvent: events.CliTestEvent{ + Name: events.DummyCliEnumValue2, }, }, }) diff --git a/libs/telemetry/events/bundle_init.go b/libs/telemetry/events/bundle_init.go new file mode 100644 index 000000000..cb303abe7 --- /dev/null +++ b/libs/telemetry/events/bundle_init.go @@ -0,0 +1,33 @@ +package events + +// Corresponds to the `DatabricksCliBundleInitEvent` proto message in `databricks_cli_log.proto` +// as of 20 Dec 2024. +type BundleInitEvent struct { + // UUID associated with the DAB itself. This is serialized into the DAB + // when a user runs `databricks bundle init` and all subsequent deployments of + // that DAB can then be associated with this init event. + Uuid string `json:"uuid,omitempty"` + + // Name of the template initialized when the user ran `databricks bundle init` + // This is only populated when the template is a first party template like + // mlops-stacks or default-python. + TemplateName BundleTemplate `json:"template_name,omitempty"` + + // Arguments used by the user to initialize the template. Only enum + // values will be set here by the Databricks CLI. + // + // We use a generic map representation here because a bundle template's args are + // managed in the template itself and maintaining a copy typed schema for it here + // will be untenable in the long term. + TemplateEnumArgs map[string]string `json:"template_enum_args,omitempty"` +} + +type BundleTemplate string + +const ( + BundleTemplateMlopsStacks BundleTemplate = "mlops-stacks" + BundleTemplateDefaultPython BundleTemplate = "default-python" + BundleTemplateDefaultSql BundleTemplate = "default-sql" + BundleTemplateDbtSql BundleTemplate = "dbt-sql" + BundleTemplateCustom BundleTemplate = "custom" +) diff --git a/libs/telemetry/events/test_event.go b/libs/telemetry/events/test_event.go new file mode 100644 index 000000000..bbd474fce --- /dev/null +++ b/libs/telemetry/events/test_event.go @@ -0,0 +1,16 @@ +package events + +// dummy event for testing the telemetry pipeline. Corresponds to `DatabricksCliTestEvent` +// proto in `databricks_cli_log.proto` as of 20 Dec 2024. +type CliTestEvent struct { + Name DummyCliEnum `json:"name,omitempty"` +} + +type DummyCliEnum string + +const ( + DummyCliEnumUnspecified DummyCliEnum = "DUMMY_CLI_ENUM_UNSPECIFIED" + DummyCliEnumValue1 DummyCliEnum = "VALUE1" + DummyCliEnumValue2 DummyCliEnum = "VALUE2" + DummyCliEnumValue3 DummyCliEnum = "VALUE3" +) diff --git a/libs/telemetry/frontend_log.go b/libs/telemetry/frontend_log.go index 915aa71ab..05960446a 100644 --- a/libs/telemetry/frontend_log.go +++ b/libs/telemetry/frontend_log.go @@ -1,5 +1,7 @@ package telemetry +import "github.com/databricks/cli/libs/telemetry/events" + // This corresponds to the FrontendLog lumberjack proto in universe. // FrontendLog is the top-level struct for any client-side logs at Databricks // regardless of whether they are generated from the CLI or the web UI. @@ -15,19 +17,6 @@ type FrontendLogEntry struct { } type DatabricksCliLog struct { - CliTestEvent CliTestEvent `json:"cli_test_event,omitempty"` + CliTestEvent events.CliTestEvent `json:"cli_test_event,omitempty"` + BundleInitEvent events.BundleInitEvent `json:"bundle_init_event,omitempty"` } - -// dummy event for testing the telemetry pipeline -type CliTestEvent struct { - Name DummyCliEnum `json:"name,omitempty"` -} - -type DummyCliEnum string - -const ( - DummyCliEnumUnspecified DummyCliEnum = "DUMMY_CLI_ENUM_UNSPECIFIED" - DummyCliEnumValue1 DummyCliEnum = "VALUE1" - DummyCliEnumValue2 DummyCliEnum = "VALUE2" - DummyCliEnumValue3 DummyCliEnum = "VALUE3" -) diff --git a/libs/telemetry/logger_test.go b/libs/telemetry/logger_test.go index c2a88d388..e0fa4332d 100644 --- a/libs/telemetry/logger_test.go +++ b/libs/telemetry/logger_test.go @@ -7,6 +7,7 @@ import ( "testing" "time" + "github.com/databricks/cli/libs/telemetry/events" "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -66,9 +67,9 @@ func TestTelemetryLoggerFlushesEvents(t *testing.T) { ctx := NewContext(context.Background()) - for _, v := range []DummyCliEnum{DummyCliEnumValue1, DummyCliEnumValue2, DummyCliEnumValue2, DummyCliEnumValue3} { + for _, v := range []events.DummyCliEnum{events.DummyCliEnumValue1, events.DummyCliEnumValue2, events.DummyCliEnumValue2, events.DummyCliEnumValue3} { err := Log(ctx, FrontendLogEntry{DatabricksCliLog: DatabricksCliLog{ - CliTestEvent: CliTestEvent{Name: v}, + CliTestEvent: events.CliTestEvent{Name: v}, }}) require.NoError(t, err) } @@ -100,9 +101,9 @@ func TestTelemetryLoggerFlushExitsOnTimeout(t *testing.T) { ctx := NewContext(context.Background()) - for _, v := range []DummyCliEnum{DummyCliEnumValue1, DummyCliEnumValue2, DummyCliEnumValue2, DummyCliEnumValue3} { + for _, v := range []events.DummyCliEnum{events.DummyCliEnumValue1, events.DummyCliEnumValue2, events.DummyCliEnumValue2, events.DummyCliEnumValue3} { err := Log(ctx, FrontendLogEntry{DatabricksCliLog: DatabricksCliLog{ - CliTestEvent: CliTestEvent{Name: v}, + CliTestEvent: events.CliTestEvent{Name: v}, }}) require.NoError(t, err) }