From 2a809c4ffb31be5d16d461fc44bc427d845d2994 Mon Sep 17 00:00:00 2001 From: Saswata Mukherjee Date: Mon, 16 Dec 2024 08:19:11 +0000 Subject: [PATCH] Address comments Signed-off-by: Saswata Mukherjee --- cmd/avalanche/avalanche.go | 10 +++++----- metrics/write.go | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/avalanche/avalanche.go b/cmd/avalanche/avalanche.go index 0e8b69e..6cb3cde 100644 --- a/cmd/avalanche/avalanche.go +++ b/cmd/avalanche/avalanche.go @@ -61,20 +61,20 @@ func main() { cfg := metrics.NewConfigFromFlags(kingpin.Flag) port := kingpin.Flag("port", "Port to serve at").Default("9001").Int() - remoteWriteConfig := metrics.NewWriteConfigFromFlags(kingpin.Flag) + writeCfg := metrics.NewWriteConfigFromFlags(kingpin.Flag) kingpin.Parse() if err := cfg.Validate(); err != nil { kingpin.FatalUsage("configuration error: %v", err) } - if err := remoteWriteConfig.Validate(); err != nil { + if err := writeCfg.Validate(); err != nil { kingpin.FatalUsage("remote write config validation failed: %v", err) } collector := metrics.NewCollector(*cfg) reg := prometheus.NewRegistry() reg.MustRegister(collector) - remoteWriteConfig.UpdateNotify = collector.UpdateNotifyCh() + writeCfg.UpdateNotify = collector.UpdateNotifyCh() log.Println("initializing avalanche...") @@ -83,10 +83,10 @@ func main() { g.Add(collector.Run, collector.Stop) // One-off remote write send mode. - if remoteWriteConfig.URL != nil { + if writeCfg.URL != nil { ctx, cancel := context.WithCancel(context.Background()) g.Add(func() error { - if err := remoteWriteConfig.SendRemoteWrite(ctx, reg); err != nil { + if err := metrics.SendRemoteWrite(ctx, writeCfg, reg); err != nil { return err } return nil // One-off. diff --git a/metrics/write.go b/metrics/write.go index 59767fc..ab7d1e8 100644 --- a/metrics/write.go +++ b/metrics/write.go @@ -109,17 +109,17 @@ type Client struct { // SendRemoteWrite initializes a http client and // sends metrics to a prometheus compatible remote endpoint. -func (c *ConfigWrite) SendRemoteWrite(ctx context.Context, gatherer prometheus.Gatherer) error { +func SendRemoteWrite(ctx context.Context, cfg *ConfigWrite, gatherer prometheus.Gatherer) error { var rt http.RoundTripper = &http.Transport{ - TLSClientConfig: &c.TLSClientConfig, + TLSClientConfig: &cfg.TLSClientConfig, } - rt = &tenantRoundTripper{tenant: c.Tenant, tenantHeader: c.TenantHeader, rt: rt} + rt = &tenantRoundTripper{tenant: cfg.Tenant, tenantHeader: cfg.TenantHeader, rt: rt} httpClient := &http.Client{Transport: rt} client := Client{ client: httpClient, timeout: time.Minute, - config: c, + config: cfg, gatherer: gatherer, } return client.write(ctx)