From 99c3f257f417900b170db8b1d6ec6b2a1ddabcb6 Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Wed, 2 Jan 2019 14:28:14 -0500 Subject: [PATCH 1/3] Removed unused code detected by staticcheck. --- cmd/stackdriver-prometheus-sidecar/main.go | 6 ------ retrieval/transform.go | 15 --------------- stackdriver/client.go | 1 - stackdriver/client_test.go | 1 - stackdriver/queue_manager.go | 5 ----- 5 files changed, 28 deletions(-) diff --git a/cmd/stackdriver-prometheus-sidecar/main.go b/cmd/stackdriver-prometheus-sidecar/main.go index 691c4a69..e063b376 100644 --- a/cmd/stackdriver-prometheus-sidecar/main.go +++ b/cmd/stackdriver-prometheus-sidecar/main.go @@ -151,12 +151,6 @@ type genericConfig struct { namespace string } -type gceMetadata struct { - projectID string - location string - cluster string -} - type fileConfig struct { MetricRenames []struct { From string `json:"from"` diff --git a/retrieval/transform.go b/retrieval/transform.go index 58eec3c8..9668895b 100644 --- a/retrieval/transform.go +++ b/retrieval/transform.go @@ -27,7 +27,6 @@ import ( "github.com/prometheus/tsdb" tsdbLabels "github.com/prometheus/tsdb/labels" distribution_pb "google.golang.org/genproto/googleapis/api/distribution" - metric_pb "google.golang.org/genproto/googleapis/api/metric" monitoring_pb "google.golang.org/genproto/googleapis/monitoring/v3" ) @@ -152,20 +151,6 @@ func getMetricType(prefix string, promName string) string { return prefix + "/" + promName } -func getMetricKind(t textparse.MetricType) metric_pb.MetricDescriptor_MetricKind { - if t == textparse.MetricTypeCounter || t == textparse.MetricTypeHistogram { - return metric_pb.MetricDescriptor_CUMULATIVE - } - return metric_pb.MetricDescriptor_GAUGE -} - -func getValueType(t textparse.MetricType) metric_pb.MetricDescriptor_ValueType { - if t == textparse.MetricTypeHistogram { - return metric_pb.MetricDescriptor_DISTRIBUTION - } - return metric_pb.MetricDescriptor_DOUBLE -} - // getTimestamp converts a millisecond timestamp into a protobuf timestamp. func getTimestamp(t int64) *timestamp_pb.Timestamp { return ×tamp_pb.Timestamp{ diff --git a/stackdriver/client.go b/stackdriver/client.go index 8cfdc5d9..80af1ecf 100644 --- a/stackdriver/client.go +++ b/stackdriver/client.go @@ -37,7 +37,6 @@ import ( ) const ( - metricsPrefix = "external.googleapis.com/prometheus" MaxTimeseriesesPerRequest = 200 MonitoringWriteScope = "https://www.googleapis.com/auth/monitoring.write" ) diff --git a/stackdriver/client_test.go b/stackdriver/client_test.go index 968b3003..4378f027 100644 --- a/stackdriver/client_test.go +++ b/stackdriver/client_test.go @@ -41,7 +41,6 @@ func newLocalListener() net.Listener { func TestStoreErrorHandling(t *testing.T) { tests := []struct { - code int status *status.Status recoverable bool }{ diff --git a/stackdriver/queue_manager.go b/stackdriver/queue_manager.go index 624fe01c..82fd53a3 100644 --- a/stackdriver/queue_manager.go +++ b/stackdriver/queue_manager.go @@ -408,7 +408,6 @@ func newShard(cfg config.QueueConfig) shard { type shardCollection struct { qm *QueueManager - client StorageClient shards []shard done chan struct{} wg sync.WaitGroup @@ -428,10 +427,6 @@ func (t *QueueManager) newShardCollection(numShards int) *shardCollection { return s } -func (s *shardCollection) len() int { - return len(s.shards) -} - func (s *shardCollection) start() { for i := range s.shards { go s.runShard(i) From 06d75e312a31d63daaf84902530382235a017dc3 Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Wed, 2 Jan 2019 14:18:18 -0500 Subject: [PATCH 2/3] Make the default URL relative This is so that any paths in the API prefix URL are preserved. E.g. `url.Parse("http://127.0.0.1:9090/foo").Parse("bar")` gives `"http://127.0.0.1:9090/foo/bar"` --- targets/cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/cache.go b/targets/cache.go index a9fe8758..28a0ec42 100644 --- a/targets/cache.go +++ b/targets/cache.go @@ -27,7 +27,7 @@ import ( "github.com/prometheus/prometheus/pkg/labels" ) -const DefaultAPIEndpoint = "/api/v1/targets" +const DefaultAPIEndpoint = "api/v1/targets" func cacheKey(job, instance string) string { return job + "\xff" + instance From b082ce211bfc00a213c067a9630e845c123d37ca Mon Sep 17 00:00:00 2001 From: Javier Kohen Date: Wed, 2 Jan 2019 14:19:05 -0500 Subject: [PATCH 3/3] Made the metadata API url relative This is so that any paths in the API prefix URL are preserved. E.g. `url.Parse("http://127.0.0.1:9090/foo").Parse("bar")` gives `"http://127.0.0.1:9090/foo/bar"` --- metadata/cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata/cache.go b/metadata/cache.go index 9015d082..76a14867 100644 --- a/metadata/cache.go +++ b/metadata/cache.go @@ -44,7 +44,7 @@ type Cache struct { // DefaultEndpointPath is the default HTTP path on which Prometheus serves // the target metadata endpoint. -const DefaultEndpointPath = "/api/v1/targets/metadata" +const DefaultEndpointPath = "api/v1/targets/metadata" // The old metric type value for textparse.MetricTypeUnknown that is used in // Prometheus 2.4 and earlier.