Emit telemetry event for bundle init

This commit is contained in:
Shreyas Goenka 2024-12-20 11:24:30 +05:30
parent 7c7f9d808d
commit 151df1c2c9
No known key found for this signature in database
GPG Key ID: 92A07DF49CCB0622
5 changed files with 63 additions and 23 deletions

View File

@ -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,
},
},
})

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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)
}