Skip to content

Commit

Permalink
feat: new version metric (#13269)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Clucas <[email protected]>
Co-authored-by: Anton Gilgur <[email protected]>
  • Loading branch information
Joibel and Anton Gilgur authored Aug 15, 2024
1 parent 312c0d0 commit cd82203
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,21 @@ A gauge of the number of queue items that have not been processed yet.

See [queue adds count](#queue_adds_count) for details.

#### `version`

Build metadata for this Controller.

| attribute | explanation |
|------------------|-------------------------------------------------------------------------------------------------------|
| `version` | The version of Argo |
| `platform` | The [Go platform](https://go.dev/doc/install/source#environment) compiled for. Example: `linux/amd64` |
| `go_version` | Version of Go used |
| `build_date` | Build date |
| `compiler` | The compiler used. Example: `gc` |
| `git_commit` | The full Git SHA1 commit |
| `git_tree_state` | Whether the Git tree was `dirty` or `clean` when built |
| `git_tag` | The Git tag or `untagged` if it was not tagged |

#### `workers_busy_count`

A count of queue workers that are busy.
Expand Down
1 change: 1 addition & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The following are new metrics:
* `queue_longest_running`
* `queue_retries`
* `queue_unfinished_work`
* `version`

and can be disabled with

Expand Down
9 changes: 9 additions & 0 deletions workflow/metrics/labels.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package metrics

const (
labelBuildVersion string = `version`
labelBuildPlatform string = `platform`
labelBuildGoVersion string = `go_version`
labelBuildDate string = `build_date`
labelBuildCompiler string = `compiler`
labelBuildGitCommit string = `git_commit`
labelBuildGitTreeState string = `git_treestate`
labelBuildGitTag string = `git_tag`

labelErrorCause string = "cause"

labelLogLevel string = `level`
Expand Down
1 change: 1 addition & 0 deletions workflow/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func New(ctx context.Context, serviceName string, config *Config, callbacks Call
addErrorCounter,
addLogCounter,
addK8sRequests,
addVersion,
addWorkflowConditionGauge,
addWorkQueueMetrics,
)
Expand Down
33 changes: 33 additions & 0 deletions workflow/metrics/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package metrics

import (
"context"

"github.com/argoproj/argo-workflows/v3"
)

func addVersion(ctx context.Context, m *Metrics) error {
const nameVersion = `version`
err := m.createInstrument(int64Counter,
nameVersion,
"Build metadata for this Controller",
"{unused}",
withAsBuiltIn(),
)
if err != nil {
return err
}

version := argo.GetVersion()
m.addInt(ctx, nameVersion, 1, instAttribs{
{name: labelBuildVersion, value: version.Version},
{name: labelBuildPlatform, value: version.Platform},
{name: labelBuildGoVersion, value: version.GoVersion},
{name: labelBuildDate, value: version.BuildDate},
{name: labelBuildCompiler, value: version.Compiler},
{name: labelBuildGitCommit, value: version.GitCommit},
{name: labelBuildGitTreeState, value: version.GitTreeState},
{name: labelBuildGitTag, value: version.GitTag},
})
return nil
}
31 changes: 31 additions & 0 deletions workflow/metrics/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package metrics

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel/attribute"

"github.com/argoproj/argo-workflows/v3"
)

func TestVersion(t *testing.T) {
_, te, err := CreateDefaultTestMetrics()
require.NoError(t, err)
assert.NotNil(t, te)
version := argo.GetVersion()
attribs := attribute.NewSet(
attribute.String(labelBuildVersion, version.Version),
attribute.String(labelBuildPlatform, version.Platform),
attribute.String(labelBuildGoVersion, version.GoVersion),
attribute.String(labelBuildDate, version.BuildDate),
attribute.String(labelBuildCompiler, version.Compiler),
attribute.String(labelBuildGitCommit, version.GitCommit),
attribute.String(labelBuildGitTreeState, version.GitTreeState),
attribute.String(labelBuildGitTag, version.GitTag),
)
val, err := te.GetInt64CounterValue(`version`, &attribs)
require.NoError(t, err)
assert.Equal(t, int64(1), val)
}

0 comments on commit cd82203

Please sign in to comment.