Skip to content

feat: add metrics to workspace agent scripts #11132

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 19 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
linting/fmt/naming
  • Loading branch information
Emyrk committed Dec 11, 2023
commit 753f1a658baaf58bd48015c75774e58a35cc2db2
8 changes: 1 addition & 7 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,17 +767,11 @@ func (a *agent) run(ctx context.Context) error {
}

dur := time.Since(start).Seconds()
// If something really look 0 ns, just set it to 1 to indicate that it ran.
// Otherwise, 0 looks like the startup script has not run yet. I don't think
// this will ever be 1ns
if dur == 0 {
dur = 1
}
label := "false"
if err == nil {
label = "true"
}
a.metrics.startScriptNs.WithLabelValues(label).Set(float64(dur))
a.metrics.startScriptSeconds.WithLabelValues(label).Set(dur)
a.scriptRunner.StartCron()
})
if err != nil {
Expand Down
15 changes: 6 additions & 9 deletions agent/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ import (
"github.com/coder/coder/v2/codersdk/agentsdk"
)



type agentMetrics struct {
connectionsTotal prometheus.Counter
reconnectingPTYErrors *prometheus.CounterVec
// startScriptNs is the time in nanoseconds that the start script(s)
// took to run. This is reported once per agent, and is collected into a
// histogram by Coder.
startScriptNs *prometheus.GaugeVec
// startScriptSeconds is the time in seconds that the start script(s)
// took to run. This is reported once per agent.
startScriptSeconds *prometheus.GaugeVec
}

func newAgentMetrics(registerer prometheus.Registerer) *agentMetrics {
Expand All @@ -41,18 +38,18 @@ func newAgentMetrics(registerer prometheus.Registerer) *agentMetrics {
)
registerer.MustRegister(reconnectingPTYErrors)

startScriptNs := prometheus.NewGaugeVec(prometheus.GaugeOpts{
startScriptSeconds := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "coderd",
Subsystem: "agentstats",
Name: "startup_script_s",
Help: "Amount of time taken to run the startup script in seconds.",
}, []string{"success"})
registerer.MustRegister(startScriptNs)
registerer.MustRegister(startScriptSeconds)

return &agentMetrics{
connectionsTotal: connectionsTotal,
reconnectingPTYErrors: reconnectingPTYErrors,
startScriptNs: startScriptNs,
startScriptSeconds: startScriptSeconds,
}
}

Expand Down
2 changes: 1 addition & 1 deletion coderd/database/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions codersdk/agentsdk/agentsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import (
"tailscale.com/tailcfg"

"cdr.dev/slog"
"github.com/coder/retry"

"github.com/coder/coder/v2/codersdk"
"github.com/coder/retry"
)

// ExternalLogSourceID is the statically-defined ID of a log-source that
Expand Down