-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tetragon-metrics-docs: Move New function to a separate package
Introduce metricsmd package containing New function from cmd/tetragon-metrics-docs. This is done so that this function can be imported and reused by different commands. Signed-off-by: Anna Kapuscinska <[email protected]>
- Loading branch information
Showing
2 changed files
with
66 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Tetragon | ||
|
||
package metricsmd | ||
|
||
import ( | ||
"log/slog" | ||
|
||
"github.com/isovalent/metricstool/pkg/metricsmd" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type initMetricsFunc func(string, *prometheus.Registry, *slog.Logger) error | ||
|
||
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. | ||
{ | ||
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"}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
config := &metricsmd.Config{ | ||
Targets: targets, | ||
LabelOverrides: overrides, | ||
InitMetrics: init, | ||
HeadingLevel: 1, | ||
} | ||
|
||
cmd, err := metricsmd.NewCmd(nil, nil, config) | ||
if err != nil { | ||
slog.Error("failed to create metrics-docs command", "error", err) | ||
} | ||
return cmd | ||
} |