From d67e4b9131941a2514b76f70380a906585cdc91a Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Thu, 7 Feb 2013 11:38:01 +0100 Subject: [PATCH] Address outstanding comments from PR/47 and other cleanups. --- LICENSE | 2 +- Makefile | 6 +-- Makefile.TRAVIS | 2 +- api/query.go | 5 ++- coding/indexable/time.go | 6 +-- coding/indexable/time_test.go | 2 +- coding/interface.go | 2 +- coding/protocol_buffer.go | 2 +- main.go | 2 +- model/Makefile | 2 +- model/data.proto | 2 +- model/dto.go | 2 +- model/metric.go | 2 +- rules/load.go | 2 +- storage/interface.go | 2 +- storage/metric/interface.go | 2 +- storage/metric/leveldb/diagnostics.go | 2 +- storage/metric/leveldb/instrumentation.go | 2 +- storage/metric/leveldb/interface_test.go | 2 +- storage/metric/leveldb/leveldb_test.go | 2 +- storage/metric/leveldb/lifecycle.go | 2 +- storage/metric/leveldb/mutable.go | 2 +- storage/metric/leveldb/reading.go | 37 +++++++------------ storage/metric/leveldb/regressions_test.go | 2 +- .../metric/leveldb/rule_integration_test.go | 2 +- storage/metric/leveldb/type.go | 2 +- storage/raw/index/interface.go | 2 +- storage/raw/index/leveldb/interface_test.go | 2 +- storage/raw/index/leveldb/leveldb.go | 2 +- storage/raw/interface.go | 2 +- storage/raw/leveldb/interface_test.go | 2 +- storage/raw/leveldb/leveldb.go | 2 +- utility/set.go | 2 +- utility/set_test.go | 2 +- utility/test/interface.go | 2 +- 35 files changed, 54 insertions(+), 62 deletions(-) diff --git a/LICENSE b/LICENSE index cbeb29fe6..b4f8761cf 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2012 Prometheus Team + Copyright 2013 Prometheus Team Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index 6c3153e12..9dc694f15 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ -# Copyright 2012 Prometheus Team +# Copyright 2013 Prometheus Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Makefile.TRAVIS b/Makefile.TRAVIS index 4eae9649d..0bd411301 100644 --- a/Makefile.TRAVIS +++ b/Makefile.TRAVIS @@ -1,4 +1,4 @@ -# Copyright 2012 Prometheus Team +# Copyright 2013 Prometheus Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/api/query.go b/api/query.go index a13bfeb5e..3041a0bfb 100644 --- a/api/query.go +++ b/api/query.go @@ -7,6 +7,7 @@ import ( "github.com/prometheus/prometheus/rules" "github.com/prometheus/prometheus/rules/ast" "log" + "net/http" "sort" "time" ) @@ -74,14 +75,14 @@ func (serv MetricsService) Metrics() string { rb.SetContentType(gorest.Application_Json) if err != nil { log.Printf("Error loading metric names: %v", err) - rb.SetResponseCode(500) + rb.SetResponseCode(http.StatusInternalServerError) return err.Error() } sort.Strings(metricNames) resultBytes, err := json.Marshal(metricNames) if err != nil { log.Printf("Error marshalling metric names: %v", err) - rb.SetResponseCode(500) + rb.SetResponseCode(http.StatusInternalServerError) return err.Error() } return string(resultBytes) diff --git a/coding/indexable/time.go b/coding/indexable/time.go index 19080fa72..930e367ae 100644 --- a/coding/indexable/time.go +++ b/coding/indexable/time.go @@ -1,10 +1,10 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/coding/indexable/time_test.go b/coding/indexable/time_test.go index 6706540f3..f24c0a07a 100644 --- a/coding/indexable/time_test.go +++ b/coding/indexable/time_test.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/coding/interface.go b/coding/interface.go index fd1c7a790..98441d68d 100644 --- a/coding/interface.go +++ b/coding/interface.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/coding/protocol_buffer.go b/coding/protocol_buffer.go index 105c3c2eb..8ad93424d 100644 --- a/coding/protocol_buffer.go +++ b/coding/protocol_buffer.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/main.go b/main.go index b5c7995dd..38c019e99 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/model/Makefile b/model/Makefile index 471ef1e2d..87d95d754 100644 --- a/model/Makefile +++ b/model/Makefile @@ -1,4 +1,4 @@ -# Copyright 2012 Prometheus Team +# Copyright 2013 Prometheus Team # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/model/data.proto b/model/data.proto index 7a957ea4d..c3ad6ab1d 100644 --- a/model/data.proto +++ b/model/data.proto @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/model/dto.go b/model/dto.go index e9695cd13..9860eadd9 100644 --- a/model/dto.go +++ b/model/dto.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/model/metric.go b/model/metric.go index 6a517a6a7..de7a7620f 100644 --- a/model/metric.go +++ b/model/metric.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/rules/load.go b/rules/load.go index bf12fdde8..c4f94235c 100644 --- a/rules/load.go +++ b/rules/load.go @@ -92,10 +92,10 @@ func LoadRulesFromString(rulesString string) ([]*Rule, error) { func LoadRulesFromFile(fileName string) ([]*Rule, error) { rulesReader, err := os.Open(fileName) - defer rulesReader.Close() if err != nil { return []*Rule{}, err } + defer rulesReader.Close() return LoadRulesFromReader(rulesReader) } diff --git a/storage/interface.go b/storage/interface.go index 0c3c722cc..2bc1b72d3 100644 --- a/storage/interface.go +++ b/storage/interface.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/interface.go b/storage/metric/interface.go index bcb03b84f..9748dedda 100644 --- a/storage/metric/interface.go +++ b/storage/metric/interface.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/leveldb/diagnostics.go b/storage/metric/leveldb/diagnostics.go index de6a72528..1c8fa98d5 100644 --- a/storage/metric/leveldb/diagnostics.go +++ b/storage/metric/leveldb/diagnostics.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/leveldb/instrumentation.go b/storage/metric/leveldb/instrumentation.go index 2bfcb6586..cad5a140b 100644 --- a/storage/metric/leveldb/instrumentation.go +++ b/storage/metric/leveldb/instrumentation.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/leveldb/interface_test.go b/storage/metric/leveldb/interface_test.go index bbd54a923..002f77852 100644 --- a/storage/metric/leveldb/interface_test.go +++ b/storage/metric/leveldb/interface_test.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/leveldb/leveldb_test.go b/storage/metric/leveldb/leveldb_test.go index d914ac28c..faef77fb1 100644 --- a/storage/metric/leveldb/leveldb_test.go +++ b/storage/metric/leveldb/leveldb_test.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/leveldb/lifecycle.go b/storage/metric/leveldb/lifecycle.go index cbe8cd1e8..683a5a239 100644 --- a/storage/metric/leveldb/lifecycle.go +++ b/storage/metric/leveldb/lifecycle.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/leveldb/mutable.go b/storage/metric/leveldb/mutable.go index ab927ed45..68409ba23 100644 --- a/storage/metric/leveldb/mutable.go +++ b/storage/metric/leveldb/mutable.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/leveldb/reading.go b/storage/metric/leveldb/reading.go index cfef876bf..98cffe1bb 100644 --- a/storage/metric/leveldb/reading.go +++ b/storage/metric/leveldb/reading.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -15,7 +15,6 @@ package leveldb import ( "code.google.com/p/goprotobuf/proto" - "errors" "github.com/prometheus/prometheus/coding" "github.com/prometheus/prometheus/coding/indexable" "github.com/prometheus/prometheus/model" @@ -644,42 +643,34 @@ func (d *MetricKeyDecoder) DecodeValue(in interface{}) (out interface{}, err err return } -type AcceptAllFilter struct{} +type MetricNamesFilter struct{} -func (f *AcceptAllFilter) Filter(key, value interface{}) (filterResult storage.FilterResult) { - return storage.ACCEPT +func (f *MetricNamesFilter) Filter(key, value interface{}) (filterResult storage.FilterResult) { + unmarshaled, ok := key.(*dto.LabelPair) + if ok && *unmarshaled.Name == "name" { + return storage.ACCEPT + } + return storage.SKIP } type CollectMetricNamesOp struct { - MetricNameMap map[string]bool + metricNames []string } func (op *CollectMetricNamesOp) Operate(key, value interface{}) (err *storage.OperatorError) { - unmarshaled, ok := key.(*dto.LabelPair) - if !ok { - return &storage.OperatorError{ - error: errors.New("Key is not of correct type"), - Continuable: true, - } - } - if *unmarshaled.Name == "name" { - op.MetricNameMap[*unmarshaled.Value] = true - } + unmarshaled := key.(*dto.LabelPair) + op.metricNames = append(op.metricNames, *unmarshaled.Value) return } func (l *LevelDBMetricPersistence) GetAllMetricNames() (metricNames []string, err error) { - metricNamesOp := &CollectMetricNamesOp{ - MetricNameMap: map[string]bool{}, - } + metricNamesOp := &CollectMetricNamesOp{} - _, err = l.labelSetToFingerprints.ForEach(&MetricKeyDecoder{}, &AcceptAllFilter{}, metricNamesOp) + _, err = l.labelSetToFingerprints.ForEach(&MetricKeyDecoder{}, &MetricNamesFilter{}, metricNamesOp) if err != nil { return } - for labelName := range metricNamesOp.MetricNameMap { - metricNames = append(metricNames, labelName) - } + metricNames = metricNamesOp.metricNames return } diff --git a/storage/metric/leveldb/regressions_test.go b/storage/metric/leveldb/regressions_test.go index 94559bc46..64c5e7735 100644 --- a/storage/metric/leveldb/regressions_test.go +++ b/storage/metric/leveldb/regressions_test.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/leveldb/rule_integration_test.go b/storage/metric/leveldb/rule_integration_test.go index c7cf6b3ad..3498bb52f 100644 --- a/storage/metric/leveldb/rule_integration_test.go +++ b/storage/metric/leveldb/rule_integration_test.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/metric/leveldb/type.go b/storage/metric/leveldb/type.go index e5c7be6f7..fb060e92e 100644 --- a/storage/metric/leveldb/type.go +++ b/storage/metric/leveldb/type.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/raw/index/interface.go b/storage/raw/index/interface.go index 7ffecd7f0..237aab85f 100644 --- a/storage/raw/index/interface.go +++ b/storage/raw/index/interface.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/raw/index/leveldb/interface_test.go b/storage/raw/index/leveldb/interface_test.go index 3b005d745..99959d02d 100644 --- a/storage/raw/index/leveldb/interface_test.go +++ b/storage/raw/index/leveldb/interface_test.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/raw/index/leveldb/leveldb.go b/storage/raw/index/leveldb/leveldb.go index df5456c95..f527da08d 100644 --- a/storage/raw/index/leveldb/leveldb.go +++ b/storage/raw/index/leveldb/leveldb.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/raw/interface.go b/storage/raw/interface.go index 67103ba2b..c552710fd 100644 --- a/storage/raw/interface.go +++ b/storage/raw/interface.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/raw/leveldb/interface_test.go b/storage/raw/leveldb/interface_test.go index 25158470f..141267a99 100644 --- a/storage/raw/leveldb/interface_test.go +++ b/storage/raw/leveldb/interface_test.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/storage/raw/leveldb/leveldb.go b/storage/raw/leveldb/leveldb.go index fffb2d4a3..a82331bc0 100644 --- a/storage/raw/leveldb/leveldb.go +++ b/storage/raw/leveldb/leveldb.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/utility/set.go b/utility/set.go index f2a565a72..fee3b37cc 100644 --- a/utility/set.go +++ b/utility/set.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/utility/set_test.go b/utility/set_test.go index 5938ed7e5..81400a333 100644 --- a/utility/set_test.go +++ b/utility/set_test.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/utility/test/interface.go b/utility/test/interface.go index e0750af3d..e46e85f9e 100644 --- a/utility/test/interface.go +++ b/utility/test/interface.go @@ -1,4 +1,4 @@ -// Copyright 2012 Prometheus Team +// Copyright 2013 Prometheus Team // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at