Skip to content

chore: add prometheus monitoring of workspace traffic generation #7583

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

Merged
merged 21 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
plumb in prom properly
  • Loading branch information
johnstcn committed May 17, 2023
commit 9a9778ce4130543c0b8719d786e4d748b19d7be2
3 changes: 2 additions & 1 deletion cli/scaletest.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
Handler: func(inv *clibase.Invocation) error {
ctx := inv.Context()
reg := prometheus.NewRegistry()
metrics := workspacetraffic.NewMetrics(reg)
metrics := workspacetraffic.NewMetrics(reg, "username", "workspace_name", "agent_name")

logger := slog.Make(sloghuman.Sink(io.Discard))
prometheusSrvClose := ServeHandler(ctx, logger, prometheusMetricsHandler(), prometheusAddress, "prometheus")
Expand Down Expand Up @@ -994,6 +994,7 @@ func (r *RootCmd) scaletestWorkspaceTraffic() *clibase.Cmd {
TickInterval: tickInterval,
WorkspaceName: ws.Name,
WorkspaceOwner: ws.OwnerName,
Registry: reg,
}

if err := config.Validate(); err != nil {
Expand Down
13 changes: 7 additions & 6 deletions scaletest/workspacetraffic/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,36 @@ type Metrics struct {
Errors prometheus.CounterVec
ReadLatencyMS prometheus.HistogramVec
WriteLatencyMS prometheus.HistogramVec
LabelNames []string
}

func NewMetrics(reg prometheus.Registerer) *Metrics {
func NewMetrics(reg prometheus.Registerer, labelNames ...string) *Metrics {
m := &Metrics{
BytesRead: *prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "coderd",
Subsystem: "scaletest",
Name: "bytes_read",
}, []string{"username", "workspace_name", "agent_name"}),
}, labelNames),
BytesWritten: *prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "coderd",
Subsystem: "scaletest",
Name: "bytes_written",
}, []string{"username", "workspace_name", "agent_name"}),
}, labelNames),
Errors: *prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "coderd",
Subsystem: "scaletest",
Name: "errors",
}, []string{"username", "workspace_name", "agent_name"}),
}, labelNames),
ReadLatencyMS: *prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "coderd",
Subsystem: "scaletest",
Name: "read_latency_seconds",
}, []string{"username", "workspace_name", "agent_name"}),
}, labelNames),
WriteLatencyMS: *prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "coderd",
Subsystem: "scaletest",
Name: "write_latency_seconds",
}, []string{"username", "workspace_name", "agent_name"}),
}, labelNames),
}

reg.MustRegister(m.BytesRead)
Expand Down
4 changes: 2 additions & 2 deletions scaletest/workspacetraffic/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (r *Runner) Run(ctx context.Context, _ string, logs io.Writer) error {
}()

// Wrap the conn in a countReadWriter so we can monitor bytes sent/rcvd.
crw := countReadWriter{ReadWriter: conn}
crw := countReadWriter{ReadWriter: conn, metrics: r.metrics, labels: []string{r.cfg.WorkspaceOwner, r.cfg.WorkspaceName, r.cfg.AgentName}}

// Create a ticker for sending data to the PTY.
tick := time.NewTicker(tickInterval)
Expand Down Expand Up @@ -188,7 +188,7 @@ type countReadWriter struct {
io.ReadWriter
bytesRead atomic.Int64
bytesWritten atomic.Int64
metrics Metrics
metrics *Metrics
labels []string
}

Expand Down