Skip to content

Commit

Permalink
Address outstanding comments from PR/47 and other cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusv committed Feb 7, 2013
1 parent abc09cf commit d67e4b9
Show file tree
Hide file tree
Showing 35 changed files with 54 additions and 62 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Makefile.TRAVIS
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions api/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/prometheus/prometheus/rules"
"github.com/prometheus/prometheus/rules/ast"
"log"
"net/http"
"sort"
"time"
)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions coding/indexable/time.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion coding/indexable/time_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion coding/interface.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion coding/protocol_buffer.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion model/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion model/data.proto
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion model/dto.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion model/metric.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion rules/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion storage/interface.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/metric/interface.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/metric/leveldb/diagnostics.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/metric/leveldb/instrumentation.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/metric/leveldb/interface_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/metric/leveldb/leveldb_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/metric/leveldb/lifecycle.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/metric/leveldb/mutable.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
37 changes: 14 additions & 23 deletions storage/metric/leveldb/reading.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion storage/metric/leveldb/regressions_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/metric/leveldb/rule_integration_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/metric/leveldb/type.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/raw/index/interface.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/raw/index/leveldb/interface_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/raw/index/leveldb/leveldb.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/raw/interface.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/raw/leveldb/interface_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion storage/raw/leveldb/leveldb.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion utility/set.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion utility/set_test.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion utility/test/interface.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit d67e4b9

Please sign in to comment.