diff --git a/.gitignore b/.gitignore index 6288bc65574..ab36077a7dd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ lib/* /tetra /tetragon-oci-hook /tetragon-oci-hook-setup +/tetragon-metrics-docs /parsertest /checkerpc observer.test diff --git a/Makefile b/Makefile index ccfdd4b377f..48b3b8166aa 100644 --- a/Makefile +++ b/Makefile @@ -437,8 +437,12 @@ kind-setup: images kind kind-install-tetragon METRICS_DOCS_PATH := docs/content/en/docs/reference/metrics.md +.PHONY: tetragon-metrics-docs +tetragon-metrics-docs: + $(GO_BUILD) ./cmd/tetragon-metrics-docs/ + .PHONY: metrics-docs -metrics-docs: tetra +metrics-docs: tetragon-metrics-docs echo '---' > $(METRICS_DOCS_PATH) echo 'title: "Metrics"' >> $(METRICS_DOCS_PATH) echo 'description: >' >> $(METRICS_DOCS_PATH) @@ -448,9 +452,9 @@ metrics-docs: tetra echo '{{< comment >}}' >> $(METRICS_DOCS_PATH) echo 'This page is autogenerated via `make metrics-doc` please do not edit directly.' >> $(METRICS_DOCS_PATH) echo '{{< /comment >}}' >> $(METRICS_DOCS_PATH) - $(CONTAINER_ENGINE) run --rm -v $(PWD):$(PWD) -w $(PWD) $(GO_IMAGE) ./tetra metrics-docs health >> $(METRICS_DOCS_PATH) - $(CONTAINER_ENGINE) run --rm -v $(PWD):$(PWD) -w $(PWD) $(GO_IMAGE) ./tetra metrics-docs resources >> $(METRICS_DOCS_PATH) - $(CONTAINER_ENGINE) run --rm -v $(PWD):$(PWD) -w $(PWD) $(GO_IMAGE) ./tetra metrics-docs events >> $(METRICS_DOCS_PATH) + $(CONTAINER_ENGINE) run --rm -v $(PWD):$(PWD) -w $(PWD) $(GO_IMAGE) ./tetragon-metrics-docs health >> $(METRICS_DOCS_PATH) + $(CONTAINER_ENGINE) run --rm -v $(PWD):$(PWD) -w $(PWD) $(GO_IMAGE) ./tetragon-metrics-docs resources >> $(METRICS_DOCS_PATH) + $(CONTAINER_ENGINE) run --rm -v $(PWD):$(PWD) -w $(PWD) $(GO_IMAGE) ./tetragon-metrics-docs events >> $(METRICS_DOCS_PATH) .PHONY: lint-metrics-md lint-metrics-md: metrics-docs diff --git a/cmd/tetra/commands_linux.go b/cmd/tetra/commands_linux.go index c7f242cc1a1..c50f70d1f54 100644 --- a/cmd/tetra/commands_linux.go +++ b/cmd/tetra/commands_linux.go @@ -6,7 +6,6 @@ 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" @@ -20,5 +19,4 @@ func addCommands(rootCmd *cobra.Command) { rootCmd.AddCommand(dump.New()) rootCmd.AddCommand(policyfilter.New()) rootCmd.AddCommand(probe.New()) - rootCmd.AddCommand(metrics.New()) } diff --git a/cmd/tetra/metrics/print.go b/cmd/tetragon-metrics-docs/main.go similarity index 85% rename from cmd/tetra/metrics/print.go rename to cmd/tetragon-metrics-docs/main.go index 4ab68732f36..1af98c31035 100644 --- a/cmd/tetra/metrics/print.go +++ b/cmd/tetragon-metrics-docs/main.go @@ -1,10 +1,11 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright Authors of Tetragon -package metrics +package main import ( "log/slog" + "os" "github.com/isovalent/metricstool/pkg/metricsmd" "github.com/prometheus/client_golang/prometheus" @@ -13,13 +14,20 @@ import ( "github.com/cilium/tetragon/pkg/metricsconfig" ) -func New() *cobra.Command { +type initMetricsFunc func(string, *prometheus.Registry, *slog.Logger) error + +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. @@ -58,7 +66,7 @@ func New() *cobra.Command { config := &metricsmd.Config{ Targets: targets, LabelOverrides: overrides, - InitMetrics: initMetrics, + InitMetrics: init, HeadingLevel: 1, }