-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logger for CLI telemetry #2083
base: refactor-bundle-init-squashed
Are you sure you want to change the base?
Add logger for CLI telemetry #2083
Conversation
// right about as the CLI command is about to exit. The API endpoint can handle | ||
// payloads with ~1000 events easily. Thus we log all the events at once instead of | ||
// batching the logs across multiple API calls. | ||
func (l *defaultLogger) Flush(ctx context.Context, apiClient DatabricksApiClient) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, this function could spawn a new process to avoid the latency cost altogether. Flushing the events to disk and having a new process consume them seems more reliable than this timeout based approach.
Integration tests are green. |
// to avoid making actual API calls. Thus WithDefaultLogger should silently | ||
// ignore the mock logger. | ||
default: | ||
panic(fmt.Errorf("unexpected telemetry logger type: %T", v)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this typecheck here? Why panic (as opposed to logging a message).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reaching here typically is a developer error. Panicking informs the developer there's a problem without having to return and propagate the error. For example, we also panic here: dbr.RunsOnRuntime(ctx)
We do the type check because we do not want to error or override if a mock logger is configured.
|
||
type mockLogger struct { | ||
events []DatabricksCliLog | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need mockLogger? The real logger already accepts interface for API call, which can be no-op in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid adding the Introspect()
method to the real logger and limit it's usage to strictly unit / integration tests.
With the mock logger you can also directly assert on a typed object for the logs / events. If we do the assertions on the apiClient directly (like we did in libs/telemetry/logger_test.go
) then you need to assert on the serialized JSON strings for the events.
Changes
Replaces #2037.
This PR adds a telemetry logger library that allows us to log arbitrary events as long as a corresponding proto exists in the universe.
We add a timeout of 3 seconds for logging the telemetry. Manual benchmarks show that API requests can take anywhere from 1-3 seconds to finish. We start here with a pragmatic approach and can improve this it of the UX in either of two ways:
Tests
Integration and unit tests.