From 71206dbc06bccab8d78b0ef1b48cacdc518a5621 Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Fri, 19 Sep 2014 18:18:44 +0200 Subject: [PATCH] More code cleanups. Add license text everywhere. And others.... Change-Id: I11ccde267a2ef7eb366c4788ba7aeae14ba7545c --- storage/local/chunk.go | 13 +++++++++++ storage/local/codec/codec_test.go | 13 +++++++++++ storage/local/delta.go | 13 +++++++++++ storage/local/index/index.go | 13 +++++++++++ storage/local/index/interface.go | 13 +++++++++++ storage/local/index/leveldb.go | 13 +++++++++++ storage/local/instrumentation.go | 2 +- storage/local/interface.go | 20 ++++++++++++---- storage/local/persistence.go | 13 +++++++++++ storage/local/persistence_test.go | 13 +++++++++++ storage/local/preload.go | 2 +- storage/local/series.go | 13 +++++++++++ storage/local/storage.go | 38 ++++++++++++++++--------------- storage/local/storage_test.go | 13 +++++++++++ storage/local/test_helpers.go | 13 +++++++++++ web/api/query.go | 2 +- 16 files changed, 182 insertions(+), 25 deletions(-) diff --git a/storage/local/chunk.go b/storage/local/chunk.go index 65eae2c0dc..c70caa3cef 100644 --- a/storage/local/chunk.go +++ b/storage/local/chunk.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package local import ( diff --git a/storage/local/codec/codec_test.go b/storage/local/codec/codec_test.go index 3dd30193b5..43c27f8800 100644 --- a/storage/local/codec/codec_test.go +++ b/storage/local/codec/codec_test.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package codec import ( diff --git a/storage/local/delta.go b/storage/local/delta.go index 6bd326b99a..33ffcb4334 100644 --- a/storage/local/delta.go +++ b/storage/local/delta.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package local import ( diff --git a/storage/local/index/index.go b/storage/local/index/index.go index 2916338fc1..7a3de7093f 100644 --- a/storage/local/index/index.go +++ b/storage/local/index/index.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + // Package index provides a number of indexes backed by persistent key-value // stores. The only supported implementation of a key-value store is currently // goleveldb, but other implementations can easily be added. diff --git a/storage/local/index/interface.go b/storage/local/index/interface.go index 7bab0bacd8..b7820925e5 100644 --- a/storage/local/index/interface.go +++ b/storage/local/index/interface.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package index import "encoding" diff --git a/storage/local/index/leveldb.go b/storage/local/index/leveldb.go index 81772f870f..8af42803bb 100644 --- a/storage/local/index/leveldb.go +++ b/storage/local/index/leveldb.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package index import ( diff --git a/storage/local/instrumentation.go b/storage/local/instrumentation.go index 41564e6889..2febf71b8b 100644 --- a/storage/local/instrumentation.go +++ b/storage/local/instrumentation.go @@ -1,4 +1,4 @@ -// Copyright 2013 Prometheus Team +// Copyright 2014 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/local/interface.go b/storage/local/interface.go index 34dbf0bb48..cb32bd16e9 100644 --- a/storage/local/interface.go +++ b/storage/local/interface.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package local import ( @@ -8,7 +21,8 @@ import ( // SeriesMap maps fingerprints to memory series. type SeriesMap map[clientmodel.Fingerprint]*memorySeries -// Storage ingests and manages samples, along with various indexes. +// Storage ingests and manages samples, along with various indexes. All methods +// are goroutine-safe. type Storage interface { // AppendSamples stores a group of new samples. Multiple samples for the same // fingerprint need to be submitted in chronological order, from oldest to @@ -24,8 +38,6 @@ type Storage interface { GetLabelValuesForLabelName(clientmodel.LabelName) clientmodel.LabelValues // Get the metric associated with the provided fingerprint. GetMetricForFingerprint(clientmodel.Fingerprint) clientmodel.Metric - // Get all label values that are associated with a given label name. - GetAllValuesForLabel(clientmodel.LabelName) clientmodel.LabelValues // Construct an iterator for a given fingerprint. NewIterator(clientmodel.Fingerprint) SeriesIterator // Run the request-serving and maintenance loop. @@ -34,7 +46,7 @@ type Storage interface { Close() error } -// SeriesIterator enables efficient access of sample values in a series +// SeriesIterator enables efficient access of sample values in a series. type SeriesIterator interface { // Gets the two values that are immediately adjacent to a given time. In // case a value exist at precisely the given time, only that single diff --git a/storage/local/persistence.go b/storage/local/persistence.go index edc64188dc..4e6ac2ce96 100644 --- a/storage/local/persistence.go +++ b/storage/local/persistence.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package local import ( diff --git a/storage/local/persistence_test.go b/storage/local/persistence_test.go index a82d52be0e..3ef92e949e 100644 --- a/storage/local/persistence_test.go +++ b/storage/local/persistence_test.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package local import ( diff --git a/storage/local/preload.go b/storage/local/preload.go index 3f05c6d783..65fc380b02 100644 --- a/storage/local/preload.go +++ b/storage/local/preload.go @@ -1,4 +1,4 @@ -// Copyright 2013 Prometheus Team +// Copyright 2014 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/local/series.go b/storage/local/series.go index cf5c03c298..4957482a1e 100644 --- a/storage/local/series.go +++ b/storage/local/series.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package local import ( diff --git a/storage/local/storage.go b/storage/local/storage.go index e475d782e1..115b50a4d2 100644 --- a/storage/local/storage.go +++ b/storage/local/storage.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + // Package local contains the local time series storage used by Prometheus. package local @@ -83,6 +96,7 @@ type persistRequest struct { chunkDesc *chunkDesc } +// AppendSamples implements Storage. func (s *memorySeriesStorage) AppendSamples(samples clientmodel.Samples) { /* s.mtx.Lock() @@ -395,13 +409,16 @@ func (s *memorySeriesStorage) Serve(started chan<- bool) { } } +// NewPreloader implements Storage. func (s *memorySeriesStorage) NewPreloader() Preloader { return &memorySeriesPreloader{ storage: s, } } +// GetFingerprintsForLabelMatchers implements Storage. func (s *memorySeriesStorage) GetFingerprintsForLabelMatchers(labelMatchers metric.LabelMatchers) clientmodel.Fingerprints { + // TODO: Is this lock needed? s.mtx.RLock() defer s.mtx.RUnlock() @@ -466,7 +483,9 @@ func (s *memorySeriesStorage) GetFingerprintsForLabelMatchers(labelMatchers metr return fps } +// GetLabelValuesForLabelName implements Storage. func (s *memorySeriesStorage) GetLabelValuesForLabelName(labelName clientmodel.LabelName) clientmodel.LabelValues { + // TODO: Is this lock needed? s.mtx.RLock() defer s.mtx.RUnlock() @@ -477,6 +496,7 @@ func (s *memorySeriesStorage) GetLabelValuesForLabelName(labelName clientmodel.L return lvs } +// GetMetricForFingerprint implements Storage. func (s *memorySeriesStorage) GetMetricForFingerprint(fp clientmodel.Fingerprint) clientmodel.Metric { s.mtx.RLock() defer s.mtx.RUnlock() @@ -497,21 +517,3 @@ func (s *memorySeriesStorage) GetMetricForFingerprint(fp clientmodel.Fingerprint } return metric } - -func (s *memorySeriesStorage) GetAllValuesForLabel(labelName clientmodel.LabelName) clientmodel.LabelValues { - s.mtx.RLock() - defer s.mtx.RUnlock() - - var values clientmodel.LabelValues - valueSet := map[clientmodel.LabelValue]struct{}{} - for _, series := range s.fingerprintToSeries { - if value, ok := series.metric[labelName]; ok { - if _, ok := valueSet[value]; !ok { - values = append(values, value) - valueSet[value] = struct{}{} - } - } - } - - return values -} diff --git a/storage/local/storage_test.go b/storage/local/storage_test.go index 56c75faaae..45ee2d3682 100644 --- a/storage/local/storage_test.go +++ b/storage/local/storage_test.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package local import ( diff --git a/storage/local/test_helpers.go b/storage/local/test_helpers.go index 8d39618ddc..238464d0e7 100644 --- a/storage/local/test_helpers.go +++ b/storage/local/test_helpers.go @@ -1,3 +1,16 @@ +// Copyright 2014 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. +// See the License for the specific language governing permissions and +// limitations under the License. + package local import ( diff --git a/web/api/query.go b/web/api/query.go index 2de82a6424..c0a6ccb971 100644 --- a/web/api/query.go +++ b/web/api/query.go @@ -137,7 +137,7 @@ func (serv MetricsService) QueryRange(w http.ResponseWriter, r *http.Request) { func (serv MetricsService) Metrics(w http.ResponseWriter, r *http.Request) { setAccessControlHeaders(w) - metricNames := serv.Storage.GetAllValuesForLabel(clientmodel.MetricNameLabel) + metricNames := serv.Storage.GetLabelValuesForLabelName(clientmodel.MetricNameLabel) sort.Sort(metricNames) resultBytes, err := json.Marshal(metricNames) if err != nil {