From acaf1d0087101c87b5b203641c4303c704009d3b Mon Sep 17 00:00:00 2001 From: "bot-ahsoka[bot]" Date: Sat, 4 Jan 2025 09:52:52 +0000 Subject: [PATCH] Updated go coverprofiles Commit: a5a4d71ea797a5dcdd5810918d5c1a536fac464c Signed-off-by: bot-ahsoka[bot] --- index.html | 79 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/index.html b/index.html index 78f015e..35c7243 100644 --- a/index.html +++ b/index.html @@ -64,8 +64,17 @@
not tracked - not covered - covered + no coverage + low coverage + * + * + * + * + * + * + * + * + high coverage
@@ -103,20 +112,20 @@ Value float64 } -func NewWriteClient(endpoint, instance, job string, reg *prometheus.Registry) (*Client, error) { - if endpoint == "" { +func NewWriteClient(endpoint, instance, job string, reg *prometheus.Registry) (*Client, error) { + if endpoint == "" { return nil, ErrMissingEndpoint{} } - if instance == "" { + if instance == "" { return nil, ErrMissingInstance{} } - if job == "" { + if job == "" { return nil, ErrMissingJob{} } - if reg == nil { + if reg == nil { return nil, ErrMissingRegistry{} } - return &Client{ + return &Client{ endpoint: endpoint, instance: instance, job: job, @@ -124,75 +133,75 @@ }, nil } -func (c *Client) Endpoint() string { - if c == nil { +func (c *Client) Endpoint() string { + if c == nil { return "" } - return c.endpoint + return c.endpoint } -func (c *Client) Registry() *prometheus.Registry { - if c == nil { +func (c *Client) Registry() *prometheus.Registry { + if c == nil { return nil } - return c.registry + return c.registry } // Set credentials needed for basic auth, return error if not provided -func (c *Client) SetBasicAuth(username, password string) error { - if username == "" || password == "" { +func (c *Client) SetBasicAuth(username, password string) error { + if username == "" || password == "" { return ErrMissingAuthCredentials{} } - c.username = username + c.username = username c.password = password return nil } // Send TimeSeries to remote_write endpoint -func (c *Client) post(ts []prompb.TimeSeries) error { +func (c *Client) post(ts []prompb.TimeSeries) error { wr := prompb.WriteRequest{Timeseries: ts} data, err := wr.Marshal() if err != nil { return err } - body := snappy.Encode(nil, data) + body := snappy.Encode(nil, data) req, err := http.NewRequest(http.MethodPost, c.Endpoint(), bytes.NewReader(body)) if err != nil { return err } - req.Header.Add("Content-Encoding", "snappy") + req.Header.Add("Content-Encoding", "snappy") req.Header.Add("Content-Type", "application/x-protobuf") req.Header.Set("X-Prometheus-Remote-Read-Version", "0.1.0") - if c.username != "" { + if c.username != "" { req.SetBasicAuth(c.username, c.password) } - httpClient := http.Client{ + httpClient := http.Client{ Timeout: time.Duration(10 * time.Second), } res, err := httpClient.Do(req) if err != nil { return err } - defer res.Body.Close() + defer res.Body.Close() if res.StatusCode != http.StatusOK { return NewErrRemoteWriteFailed(res.StatusCode, req.Body) } - return nil + return nil } // Collect metrics from registry and convert them to TimeSeries -func (c *Client) collect() ([]prompb.TimeSeries, error) { +func (c *Client) collect() ([]prompb.TimeSeries, error) { ch := make(chan prometheus.Metric) - go func() { + go func() { c.registry.Collect(ch) close(ch) }() - var res []prompb.TimeSeries - for metric := range ch { + var res []prompb.TimeSeries + for metric := range ch { // Extract name of metric regex := regexp.MustCompile("fqName: \"([a-zA-Z_:][a-zA-Z0-9_:]*)\"") fqName := regex.FindStringSubmatch(metric.Desc().String()) @@ -201,14 +210,14 @@ } // Convert metric to readable format - m := &dto.Metric{} + m := &dto.Metric{} err := metric.Write(m) if err != nil { return nil, err } // Extract lables - labels := make([]prompb.Label, len(m.Label)+3) + labels := make([]prompb.Label, len(m.Label)+3) labels[0] = prompb.Label{ Name: "__name__", Value: fqName[1], @@ -221,14 +230,14 @@ Name: "job", Value: c.job, } - for i, l := range m.Label { + for i, l := range m.Label { labels[i+3] = prompb.Label{ Name: l.GetName(), Value: l.GetValue(), } } - ts := prompb.TimeSeries{ + ts := prompb.TimeSeries{ Labels: labels, } @@ -236,14 +245,14 @@ var value float64 if m.Counter != nil { value = m.Counter.GetValue() - } else if m.Gauge != nil { + } else if m.Gauge != nil { value = m.Gauge.GetValue() } else if m.Untyped != nil { value = m.Counter.GetValue() } else { return nil, fmt.Errorf("Unknown metric type") } - ts.Samples = []prompb.Sample{ + ts.Samples = []prompb.Sample{ { Value: value, Timestamp: timestamp.FromTime(time.Now()), @@ -252,7 +261,7 @@ res = append(res, ts) } - return res, nil + return res, nil } // Collect metrics and send them to remote server in interval.