Skip to content

Commit

Permalink
send otel metrics related to keyboard feature
Browse files Browse the repository at this point in the history
Signed-off-by: Joana Hrotko <joana.hrotko@docker.com>
  • Loading branch information
jhrotko committed Mar 15, 2024
1 parent ee4834f commit ae6b3fa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/formatter/shortcut.go
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/buger/goterm"
"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/compose/v2/internal/tracing"
"github.com/docker/compose/v2/pkg/api"
"github.com/docker/compose/v2/pkg/watch"
"github.com/eiannone/keyboard"
Expand Down Expand Up @@ -48,6 +49,7 @@ type LogKeyboard struct {
// services []string
// printerStop func()
// printerStart func()
metrics tracing.KeyboardMetrics
}

var KeyboardManager *LogKeyboard
Expand All @@ -66,6 +68,10 @@ func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<-
km.Watch.Watching = false
km.Watch.WatchFn = watchFn
km.SignalChannel = sc
km.metrics = tracing.KeyboardMetrics{
EnabledViewDockerDesktop: isDockerDesktopActive,
HasWatchConfig: isWatchConfigured,
}
KeyboardManager = &km
}

Expand Down Expand Up @@ -180,6 +186,7 @@ func (lk *LogKeyboard) openDockerDesktop(project *types.Project) {
if !lk.IsDockerDesktopActive {
return
}
lk.metrics.ActivateViewDockerDesktop = true
link := fmt.Sprintf("docker-desktop://dashboard/apps/%s", project.Name)
err := open.Run(link)
if err != nil {
Expand Down Expand Up @@ -291,6 +298,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
case 'V':
lk.openDockerDesktop(project)
case 'W':
lk.metrics.ActivateWatch = true
lk.StartWatch(ctx, project, options)
// case 'D':
// lk.debug(project)
Expand All @@ -304,6 +312,13 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
lk.Watch.Cancel()
_ = eg.Wait().ErrorOrNil() // Need to print this ?
}
go func() {
tracing.SpanWrapFunc("nav_menu", tracing.KeyboardOptions(lk.metrics),
func(ctx context.Context) error {
return nil
})(ctx)
}()

// will notify main thread to kill and will handle gracefully
lk.SignalChannel <- syscall.SIGINT
case keyboard.KeyEnter:
Expand Down
19 changes: 19 additions & 0 deletions internal/tracing/attributes.go
Expand Up @@ -42,6 +42,13 @@ type Metrics struct {
CountIncludesRemote int
}

type KeyboardMetrics struct {
EnabledViewDockerDesktop bool
HasWatchConfig bool
ActivateViewDockerDesktop bool
ActivateWatch bool
}

func (s SpanOptions) SpanStartOptions() []trace.SpanStartOption {
out := make([]trace.SpanStartOption, len(s))
for i := range s {
Expand Down Expand Up @@ -135,6 +142,18 @@ func ServiceOptions(service types.ServiceConfig) SpanOptions {
}
}

func KeyboardOptions(metrics KeyboardMetrics) SpanOptions {
attrs := []attribute.KeyValue{
attribute.Bool("view.enabled", metrics.EnabledViewDockerDesktop),
attribute.Bool("view.activated", metrics.ActivateViewDockerDesktop),
attribute.Bool("watch.activated", metrics.ActivateWatch),
attribute.Bool("watch.config", metrics.HasWatchConfig),
}
return []trace.SpanStartEventOption{
trace.WithAttributes(attrs...),
}
}

// ContainerOptions returns common attributes from a Moby container.
//
// For convenience, it's returned as a SpanOptions object to allow it to be
Expand Down

0 comments on commit ae6b3fa

Please sign in to comment.