Skip to content

Commit

Permalink
Emit telemetry event for bundle init
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-goenka committed Dec 20, 2024
1 parent a4f5d89 commit 5a44895
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 26 deletions.
15 changes: 8 additions & 7 deletions internal/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"testing"
"time"

"github.com/databricks/cli/internal/acc"
"github.com/databricks/cli/integration/internal/acc"

Check failure on line 9 in internal/telemetry_test.go

View workflow job for this annotation

GitHub Actions / lint

use of internal package github.com/databricks/cli/integration/internal/acc not allowed (typecheck)

Check failure on line 9 in internal/telemetry_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

use of internal package github.com/databricks/cli/integration/internal/acc not allowed

Check failure on line 9 in internal/telemetry_test.go

View workflow job for this annotation

GitHub Actions / tests (macos-latest)

use of internal package github.com/databricks/cli/integration/internal/acc not allowed

Check failure on line 9 in internal/telemetry_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

use of internal package github.com/databricks/cli/integration/internal/acc not allowed

Check failure on line 9 in internal/telemetry_test.go

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

use of internal package github.com/databricks/cli/integration/internal/acc not allowed

Check failure on line 9 in internal/telemetry_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

use of internal package github.com/databricks/cli/integration/internal/acc not allowed

Check failure on line 9 in internal/telemetry_test.go

View workflow job for this annotation

GitHub Actions / tests (windows-latest)

use of internal package github.com/databricks/cli/integration/internal/acc not allowed
"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"
Expand All @@ -22,8 +23,8 @@ type apiClientWrapper struct {

func (wrapper *apiClientWrapper) Do(ctx context.Context, method, path string,
headers map[string]string, request, response any,
visitors ...func(*http.Request) error) error {

visitors ...func(*http.Request) error,
) error {
err := wrapper.apiClient.Do(ctx, method, path, headers, request, response, visitors...)
wrapper.response = response.(*telemetry.ResponseBody)
return err
Expand All @@ -42,15 +43,15 @@ func TestAccTelemetryLogger(t *testing.T) {
// Log some events.
telemetry.Log(ctx, telemetry.FrontendLogEntry{
DatabricksCliLog: telemetry.DatabricksCliLog{
CliTestEvent: telemetry.CliTestEvent{
Name: telemetry.DummyCliEnumValue1,
CliTestEvent: events.CliTestEvent{
Name: events.DummyCliEnumValue1,
},
},
})
telemetry.Log(ctx, telemetry.FrontendLogEntry{
DatabricksCliLog: telemetry.DatabricksCliLog{
CliTestEvent: telemetry.CliTestEvent{
Name: telemetry.DummyCliEnumValue2,
CliTestEvent: events.CliTestEvent{
Name: events.DummyCliEnumValue2,
},
},
})
Expand Down
33 changes: 33 additions & 0 deletions libs/telemetry/events/bundle_init.go
Original file line number Diff line number Diff line change
@@ -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"
)
16 changes: 16 additions & 0 deletions libs/telemetry/events/test_event.go
Original file line number Diff line number Diff line change
@@ -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"
)
19 changes: 4 additions & 15 deletions libs/telemetry/frontend_log.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,19 +17,6 @@ type FrontendLogEntry struct {
}

type DatabricksCliLog struct {
CliTestEvent CliTestEvent `json:"cli_test_event,omitempty"`
}

// dummy event for testing the telemetry pipeline
type CliTestEvent struct {
Name DummyCliEnum `json:"name,omitempty"`
CliTestEvent events.CliTestEvent `json:"cli_test_event,omitempty"`
BundleInitEvent events.BundleInitEvent `json:"bundle_init_event,omitempty"`
}

type DummyCliEnum string

const (
DummyCliEnumUnspecified DummyCliEnum = "DUMMY_CLI_ENUM_UNSPECIFIED"
DummyCliEnumValue1 DummyCliEnum = "VALUE1"
DummyCliEnumValue2 DummyCliEnum = "VALUE2"
DummyCliEnumValue3 DummyCliEnum = "VALUE3"
)
9 changes: 5 additions & 4 deletions libs/telemetry/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 5a44895

Please sign in to comment.