Merge pull request #62 from prometheus/julius-cleanups

Address outstanding comments from PR/47 and other cleanups.
This commit is contained in:
Matt T. Proud 2013-02-07 02:42:30 -08:00
commit d8c4f2c3c9
35 changed files with 54 additions and 62 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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