Skip to content

Commit

Permalink
cmd: Refactor tetragon-metrics-docs command
Browse files Browse the repository at this point in the history
Targets and InitMetrics function are now passed as arguments to the New
function. This is done so that the New function can be reused to generate
different references (e.g. for different metrics groups).

Signed-off-by: Anna Kapuscinska <[email protected]>
  • Loading branch information
lambdanis committed Jun 27, 2024
1 parent bad3aed commit 0d85b38
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cmd/tetragon-metrics-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ import (
"github.com/cilium/tetragon/pkg/metricsconfig"
)

func main() {
if err := New().Execute(); err != nil {
os.Exit(1)
}
}
type initMetricsFunc func(string, *prometheus.Registry, *slog.Logger) error

func New() *cobra.Command {
func main() {
targets := map[string]string{
"health": "Tetragon Health",
"resources": "Tetragon Resources",
"events": "Tetragon Events",
}
if err := New(targets, initMetrics).Execute(); err != nil {
os.Exit(1)
}
}

func New(targets map[string]string, init initMetricsFunc) *cobra.Command {
overrides := []metricsmd.LabelOverrides{
// Theses metrics takes VCS info into account supplied at build
// time, which changes every build, so override those.
Expand Down Expand Up @@ -65,7 +66,7 @@ func New() *cobra.Command {
config := &metricsmd.Config{
Targets: targets,
LabelOverrides: overrides,
InitMetrics: initMetrics,
InitMetrics: init,
HeadingLevel: 1,
}

Expand Down

0 comments on commit 0d85b38

Please sign in to comment.