From dff2224ce180bc5f7eac2baabdb93ae365dd9add Mon Sep 17 00:00:00 2001 From: Anton Petruhin Date: Thu, 11 Apr 2024 13:46:06 +0400 Subject: [PATCH 1/3] metrics: set `info` log level --- prom/agent.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/prom/agent.go b/prom/agent.go index 1b819c1..95adcee 100644 --- a/prom/agent.go +++ b/prom/agent.go @@ -5,6 +5,7 @@ import ( "github.com/coroot/coroot-node-agent/common" "github.com/coroot/coroot-node-agent/flags" + "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" promConfig "github.com/prometheus/common/config" "github.com/prometheus/common/model" @@ -25,12 +26,12 @@ const ( ) func StartAgent(machineId string) error { - l := Logger{} + logger := level.NewFilter(Logger{}, level.AllowInfo()) if *flags.MetricsEndpoint == nil { return nil } - klog.Infoln("Metrics remote write endpoint:", (*flags.MetricsEndpoint).String()) + klog.Infoln("metrics remote write endpoint:", (*flags.MetricsEndpoint).String()) cfg := config.DefaultConfig cfg.GlobalConfig.ScrapeInterval = model.Duration(*flags.ScrapeInterval) cfg.GlobalConfig.ScrapeTimeout = model.Duration(*flags.ScrapeInterval) @@ -54,14 +55,14 @@ func StartAgent(machineId string) error { opts := agent.DefaultOptions() localStorage := &readyStorage{stats: tsdb.NewDBStats()} scraper := &readyScrapeManager{} - remoteStorage := remote.NewStorage(l, prometheus.DefaultRegisterer, localStorage.StartTime, *flags.WalDir, RemoteFlushDeadline, scraper) - fanoutStorage := storage.NewFanout(l, localStorage, remoteStorage) + remoteStorage := remote.NewStorage(logger, prometheus.DefaultRegisterer, localStorage.StartTime, *flags.WalDir, RemoteFlushDeadline, scraper) + fanoutStorage := storage.NewFanout(logger, localStorage, remoteStorage) if err := remoteStorage.ApplyConfig(&cfg); err != nil { return err } - scrapeManager, err := scrape.NewManager(nil, l, fanoutStorage, prometheus.DefaultRegisterer) + scrapeManager, err := scrape.NewManager(nil, logger, fanoutStorage, prometheus.DefaultRegisterer) if err != nil { return err } @@ -69,7 +70,7 @@ func StartAgent(machineId string) error { return err } scraper.Set(scrapeManager) - db, err := agent.Open(l, prometheus.DefaultRegisterer, remoteStorage, *flags.WalDir, opts) + db, err := agent.Open(logger, prometheus.DefaultRegisterer, remoteStorage, *flags.WalDir, opts) if err != nil { return err } From 44f6e37e99a9abbc9b06f794410493b6e4bc9212 Mon Sep 17 00:00:00 2001 From: Anton Petruhin Date: Thu, 11 Apr 2024 13:47:17 +0400 Subject: [PATCH 2/3] profiling: set `SampleType` name --- profiling/profiling.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/profiling/profiling.go b/profiling/profiling.go index cc600c4..70dffe5 100644 --- a/profiling/profiling.go +++ b/profiling/profiling.go @@ -54,7 +54,6 @@ func Init(hostId, hostName string) chan<- containers.ProcessInfo { constLabels = labels.Labels{ {Name: "host.name", Value: hostName}, {Name: "host.id", Value: hostId}, - {Name: "profile.source", Value: "ebpf"}, } reg := prometheus.NewRegistry() @@ -167,6 +166,7 @@ func upload(b *pprof.ProfileBuilder) error { } u.RawQuery = q.Encode() + b.Profile.SampleType[0].Type = "ebpf:cpu:nanoseconds" b.Profile.DurationNanos = CollectInterval.Nanoseconds() body := bytes.NewBuffer(nil) _, err := b.Write(body) @@ -174,7 +174,7 @@ func upload(b *pprof.ProfileBuilder) error { return err } - req, err := http.NewRequest("POST", u.String(), body) + req, err := http.NewRequest(http.MethodPost, u.String(), body) if err != nil { return err } From e68f0610d8c3aba2f447cd3ed8a73837e7e6be4f Mon Sep 17 00:00:00 2001 From: Anton Petruhin Date: Thu, 11 Apr 2024 13:49:00 +0400 Subject: [PATCH 3/3] flags: add base `collector endpoint` URL --- flags/flags.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/flags/flags.go b/flags/flags.go index a9217b3..8e86e1c 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -25,14 +25,15 @@ var ( LogPerSecond = kingpin.Flag("log-per-second", "The number of logs per second").Default("10.0").Envar("LOG_PER_SECOND").Float64() LogBurst = kingpin.Flag("log-burst", "The maximum number of tokens that can be consumed in a single call to allow").Default("100").Envar("LOG_BURST").Int() - MetricsEndpoint = kingpin.Flag("metrics-endpoint", "The URL of the endpoint to send metrics to").Envar("METRICS_ENDPOINT").URL() - TracesEndpoint = kingpin.Flag("traces-endpoint", "The URL of the endpoint to send traces to").Envar("TRACES_ENDPOINT").URL() - LogsEndpoint = kingpin.Flag("logs-endpoint", "The URL of the endpoint to send logs to").Envar("LOGS_ENDPOINT").URL() - ProfilesEndpoint = kingpin.Flag("profiles-endpoint", "The URL of the endpoint to send profiles to").Envar("PROFILES_ENDPOINT").URL() - ApiKey = kingpin.Flag("api-key", "Coroot API key").Envar("API_KEY").String() - ScrapeInterval = kingpin.Flag("scrape-interval", "How often to gather metrics from the agent").Default("15s").Envar("SCRAPE_INTERVAL").Duration() - - WalDir = kingpin.Flag("wal-dir", "Path to where the agent stores data (e.g. the metrics Write-Ahead Log)").Default("/tmp/coroot-node-agent").Envar("WAL_DIR").String() + CollectorEndpoint = kingpin.Flag("collector-endpoint", "A base endpoint URL for metrics, traces, logs, and profiles").Envar("COLLECTOR_ENDPOINT").URL() + ApiKey = kingpin.Flag("api-key", "Coroot API key").Envar("API_KEY").String() + MetricsEndpoint = kingpin.Flag("metrics-endpoint", "The URL of the endpoint to send metrics to").Envar("METRICS_ENDPOINT").URL() + TracesEndpoint = kingpin.Flag("traces-endpoint", "The URL of the endpoint to send traces to").Envar("TRACES_ENDPOINT").URL() + LogsEndpoint = kingpin.Flag("logs-endpoint", "The URL of the endpoint to send logs to").Envar("LOGS_ENDPOINT").URL() + ProfilesEndpoint = kingpin.Flag("profiles-endpoint", "The URL of the endpoint to send profiles to").Envar("PROFILES_ENDPOINT").URL() + + ScrapeInterval = kingpin.Flag("scrape-interval", "How often to gather metrics from the agent").Default("15s").Envar("SCRAPE_INTERVAL").Duration() + WalDir = kingpin.Flag("wal-dir", "Path to where the agent stores data (e.g. the metrics Write-Ahead Log)").Default("/tmp/coroot-node-agent").Envar("WAL_DIR").String() ) func GetString(fl *string) string { @@ -46,6 +47,23 @@ func init() { if strings.HasSuffix(os.Args[0], ".test") { return } + kingpin.HelpFlag.Short('h').Hidden() kingpin.Parse() + + if *CollectorEndpoint != nil { + u := *CollectorEndpoint + if *MetricsEndpoint == nil { + *MetricsEndpoint = u.JoinPath("/v1/metrics") + } + if *TracesEndpoint == nil { + *TracesEndpoint = u.JoinPath("/v1/traces") + } + if *LogsEndpoint == nil { + *LogsEndpoint = u.JoinPath("/v1/logs") + } + if *ProfilesEndpoint == nil { + *ProfilesEndpoint = u.JoinPath("/v1/profiles") + } + } }