Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cmd: Move metrics-docs out of tetra and refactor it #2611

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lib/*
/tetra
/tetragon-oci-hook
/tetragon-oci-hook-setup
/tetragon-metrics-docs
/parsertest
/checkerpc
observer.test
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions cmd/tetra/commands_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
}
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -58,7 +66,7 @@ func New() *cobra.Command {
config := &metricsmd.Config{
Targets: targets,
LabelOverrides: overrides,
InitMetrics: initMetrics,
InitMetrics: init,
HeadingLevel: 1,
}

Expand Down
Loading