Skip to content

Commit

Permalink
tetra: Add metrics-docs command
Browse files Browse the repository at this point in the history
This command utilizes github.com/isovalent/metricstool/pkg/metricsmd to
generate a metrics reference.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
  • Loading branch information
lambdanis committed Feb 20, 2024
1 parent 2e3d543 commit c315ad2
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/tetra/commands_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"github.com/cilium/tetragon/cmd/tetra/bugtool"
"github.com/cilium/tetragon/cmd/tetra/dump"
"github.com/cilium/tetragon/cmd/tetra/metrics"
"github.com/cilium/tetragon/cmd/tetra/policyfilter"
"github.com/cilium/tetragon/cmd/tetra/probe"
"github.com/cilium/tetragon/cmd/tetra/tracingpolicy"
Expand All @@ -19,4 +20,5 @@ func addCommands(rootCmd *cobra.Command) {
rootCmd.AddCommand(dump.New())
rootCmd.AddCommand(policyfilter.New())
rootCmd.AddCommand(probe.New())
rootCmd.AddCommand(metrics.New())
}
62 changes: 62 additions & 0 deletions cmd/tetra/metrics/print.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Tetragon

package metrics

import (
"log/slog"

"github.com/isovalent/metricstool/pkg/metricsmd"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cobra"

"github.com/cilium/tetragon/pkg/metrics/metricsconfig"
)

func New() *cobra.Command {
targets := map[string]string{
"tetragon": "Tetragon",
}

overrides := []metricsmd.LabelOverrides{
// Theses metrics takes VCS info into account supplied at build
// time, which changes every build, so override those.
{
Metric: "go_info",
Overrides: []metricsmd.LabelValues{
{
Label: "version",
Values: []string{"go1.22.0"},
},
},
},
{
Metric: "tetragon_build_info",
Overrides: []metricsmd.LabelValues{
{
Label: "commit",
Values: []string{"931b70f2c9878ba985ba6b589827bea17da6ec33"},
},
{
Label: "go_version",
Values: []string{"go1.22.0"},
},
{
Label: "modified",
Values: []string{"false"},
},
{
Label: "time",
Values: []string{"2022-05-13T15:54:45Z"},
},
},
},
}

return metricsmd.NewCmd(nil, nil, map[string]string{}, targets, overrides, initMetrics)
}

func initMetrics(_ string, reg *prometheus.Registry, _ *slog.Logger) error {
metricsconfig.InitAllMetrics(reg)
return nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/iancoleman/strcase v0.3.0
github.com/isovalent/metricstool v0.0.0-20240220124724-285815580016
github.com/jpillora/longestcommon v0.0.0-20161227235612-adb9d91ee629
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/mennanov/fieldmask-utils v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/isovalent/metricstool v0.0.0-20240220124724-285815580016 h1:8kTfM4TIcCeKUfD0ct45SHLUgIqBB391be1HuyjaKVc=
github.com/isovalent/metricstool v0.0.0-20240220124724-285815580016/go.mod h1:ol80lPphlGYFS16mc54bPVudTT8GkIaHwRMiUuya0sY=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down
201 changes: 201 additions & 0 deletions vendor/github.com/isovalent/metricstool/LICENSE

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

103 changes: 103 additions & 0 deletions vendor/github.com/isovalent/metricstool/pkg/metricsmd/generate.go

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

Loading

0 comments on commit c315ad2

Please sign in to comment.