diff --git a/go.mod b/go.mod index 0d02cb28..e79dec2c 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/gorilla/websocket v1.4.2 github.com/kelseyhightower/envconfig v1.4.0 github.com/pkg/errors v0.9.1 - github.com/prometheus/client_golang v1.6.0 + github.com/prometheus/client_golang v1.7.0 github.com/prometheus/common v0.10.0 github.com/prometheus/prometheus v1.8.2-0.20200507164740-ecee9c8abfd1 github.com/rakyll/statik v0.1.7 diff --git a/go.sum b/go.sum index 721a5c0c..171b4578 100644 --- a/go.sum +++ b/go.sum @@ -306,6 +306,8 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -430,6 +432,8 @@ github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46O github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jsternberg/zap-logfmt v1.0.0/go.mod h1:uvPs/4X51zdkcm5jXl5SYoN+4RK21K8mysFmDaM/h+o= @@ -590,8 +594,8 @@ github.com/prometheus/client_golang v1.3.0 h1:miYCvYqFXtl/J9FIy8eNpBfYthAEFg+Ys0 github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= -github.com/prometheus/client_golang v1.6.0 h1:YVPodQOcK15POxhgARIvnDRVpLcuK8mglnMrWfyrw6A= -github.com/prometheus/client_golang v1.6.0/go.mod h1:ZLOG9ck3JLRdB5MgO8f+lLTe83AXG6ro35rLTxvnIl4= +github.com/prometheus/client_golang v1.7.0 h1:wCi7urQOGBsYcQROHqpUUX4ct84xp40t9R9JX0FuA/U= +github.com/prometheus/client_golang v1.7.0/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -618,6 +622,8 @@ github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLk github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/procfs v0.0.11 h1:DhHlBtkHWPYi8O2y31JkK0TF+DGM+51OopZjH/Ia5qI= github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= +github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/prometheus v1.8.2-0.20200507164740-ecee9c8abfd1 h1:Oh/bmW9DXCbMeAZbxMmt2wuY6Q4cD0IIbR6vJP3kdHg= github.com/prometheus/prometheus v1.8.2-0.20200507164740-ecee9c8abfd1/go.mod h1:S5n0C6tSgdnwWshBUceRx5G1OsjLv/EeZ9t3wIfEtsY= github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= @@ -872,6 +878,8 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f h1:gWF768j/LaZugp8dyS4UwsslYCYz9XgFxvlgsn0n9H8= golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1013,6 +1021,8 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/langserver/completion.go b/langserver/completion.go index f5d2faea..f300215c 100644 --- a/langserver/completion.go +++ b/langserver/completion.go @@ -355,7 +355,7 @@ OUTER: // nolint: funlen func (s *server) completeLabelValue(ctx context.Context, completions *[]protocol.CompletionItem, location *cache.Location, labelName string) error { - labelValues, err := s.metadataService.LabelValues(ctx, labelName) + labelValues, err := s.metadataService.LabelValues(ctx, labelName, time.Now().Add(-100*time.Hour), time.Now()) if err != nil { // nolint: errcheck s.client.LogMessage(s.lifetime, &protocol.LogMessageParams{ diff --git a/prometheus/compatible.go b/prometheus/compatible.go index cd4cbf5c..591ab76a 100644 --- a/prometheus/compatible.go +++ b/prometheus/compatible.go @@ -46,9 +46,10 @@ func (c *compatibleHTTPClient) AllMetricMetadata(ctx context.Context) (map[strin return c.prometheusClient.Metadata(ctx, "", "") } -func (c *compatibleHTTPClient) LabelNames(ctx context.Context, name string, startTime time.Time, endTime time.Time) ([]string, error) { +func (c *compatibleHTTPClient) LabelNames(ctx context.Context, name string, + startTime time.Time, endTime time.Time) ([]string, error) { if len(name) == 0 { - names, _, err := c.prometheusClient.LabelNames(ctx) + names, _, err := c.prometheusClient.LabelNames(ctx, startTime, endTime) return names, err } labelNames, _, err := c.prometheusClient.Series(ctx, []string{name}, startTime, endTime) @@ -69,8 +70,9 @@ func (c *compatibleHTTPClient) LabelNames(ctx context.Context, name string, star return result, nil } -func (c *compatibleHTTPClient) LabelValues(ctx context.Context, label string) ([]model.LabelValue, error) { - values, _, err := c.prometheusClient.LabelValues(ctx, label) +func (c *compatibleHTTPClient) LabelValues(ctx context.Context, label string, + startTime time.Time, endTime time.Time) ([]model.LabelValue, error) { + values, _, err := c.prometheusClient.LabelValues(ctx, label, startTime, endTime) return values, err } diff --git a/prometheus/empty.go b/prometheus/empty.go index 42b0b878..ad27d533 100644 --- a/prometheus/empty.go +++ b/prometheus/empty.go @@ -38,7 +38,7 @@ func (c *emptyHTTPClient) LabelNames(_ context.Context, _ string, _ time.Time, _ return []string{}, nil } -func (c *emptyHTTPClient) LabelValues(_ context.Context, _ string) ([]model.LabelValue, error) { +func (c *emptyHTTPClient) LabelValues(_ context.Context, _ string, _ time.Time, _ time.Time) ([]model.LabelValue, error) { return []model.LabelValue{}, nil } diff --git a/prometheus/metadata_service.go b/prometheus/metadata_service.go index e63710ef..967aeb3e 100644 --- a/prometheus/metadata_service.go +++ b/prometheus/metadata_service.go @@ -94,7 +94,7 @@ type MetadataService interface { // If a metric is provided, then it will return all unique label names linked to the metric during a predefined period of time LabelNames(ctx context.Context, metricName string, startTime time.Time, endTime time.Time) ([]string, error) // LabelValues performs a query for the values of the given label. - LabelValues(ctx context.Context, label string) ([]model.LabelValue, error) + LabelValues(ctx context.Context, label string, startTime time.Time, endTime time.Time) ([]model.LabelValue, error) // ChangeDataSource is used if the prometheusURL is changing. // The client should re init its own parameter accordingly if necessary ChangeDataSource(prometheusURL string) error @@ -136,16 +136,18 @@ func (c *httpClient) AllMetricMetadata(ctx context.Context) (map[string][]v1.Met return c.subClient.AllMetricMetadata(ctx) } -func (c *httpClient) LabelNames(ctx context.Context, name string, startTime time.Time, endTime time.Time) ([]string, error) { +func (c *httpClient) LabelNames(ctx context.Context, name string, + startTime time.Time, endTime time.Time) ([]string, error) { c.mutex.RLock() defer c.mutex.RUnlock() return c.subClient.LabelNames(ctx, name, startTime, endTime) } -func (c *httpClient) LabelValues(ctx context.Context, label string) ([]model.LabelValue, error) { +func (c *httpClient) LabelValues(ctx context.Context, label string, + startTime time.Time, endTime time.Time) ([]model.LabelValue, error) { c.mutex.RLock() defer c.mutex.RUnlock() - return c.subClient.LabelValues(ctx, label) + return c.subClient.LabelValues(ctx, label, startTime, endTime) } func (c *httpClient) GetURL() string { diff --git a/prometheus/not_compatible.go b/prometheus/not_compatible.go index a0408a23..990799fb 100644 --- a/prometheus/not_compatible.go +++ b/prometheus/not_compatible.go @@ -43,7 +43,7 @@ func (c *notCompatibleHTTPClient) MetricMetadata(ctx context.Context, metric str } func (c *notCompatibleHTTPClient) AllMetricMetadata(ctx context.Context) (map[string][]v1.Metadata, error) { - metricNames, _, err := c.prometheusClient.LabelValues(ctx, "__name__") + metricNames, _, err := c.prometheusClient.LabelValues(ctx, "__name__", time.Now().Add(-100*time.Hour), time.Now()) if err != nil { return nil, err } @@ -54,9 +54,10 @@ func (c *notCompatibleHTTPClient) AllMetricMetadata(ctx context.Context) (map[st return allMetadata, nil } -func (c *notCompatibleHTTPClient) LabelNames(ctx context.Context, name string, startTime time.Time, endTime time.Time) ([]string, error) { +func (c *notCompatibleHTTPClient) LabelNames(ctx context.Context, name string, + startTime time.Time, endTime time.Time) ([]string, error) { if len(name) == 0 { - names, _, err := c.prometheusClient.LabelNames(ctx) + names, _, err := c.prometheusClient.LabelNames(ctx, startTime, endTime) return names, err } labelNames, _, err := c.prometheusClient.Series(ctx, []string{name}, startTime, endTime) @@ -77,8 +78,9 @@ func (c *notCompatibleHTTPClient) LabelNames(ctx context.Context, name string, s return result, nil } -func (c *notCompatibleHTTPClient) LabelValues(ctx context.Context, label string) ([]model.LabelValue, error) { - values, _, err := c.prometheusClient.LabelValues(ctx, label) +func (c *notCompatibleHTTPClient) LabelValues(ctx context.Context, label string, + startTime time.Time, endTime time.Time) ([]model.LabelValue, error) { + values, _, err := c.prometheusClient.LabelValues(ctx, label, startTime, endTime) return values, err }