diff --git a/Makefile.TRAVIS b/Makefile.TRAVIS index e353ab73e..5fc39c207 100644 --- a/Makefile.TRAVIS +++ b/Makefile.TRAVIS @@ -40,7 +40,7 @@ preparation-stamp: build-dependencies build-dependencies: build-dependencies-stamp -build-dependencies-stamp: bison cc mercurial protoc goprotobuf go leveldb levigo gorest +build-dependencies-stamp: bison cc mercurial protoc goprotobuf go leveldb levigo touch $@ overlay: overlay-stamp @@ -139,13 +139,6 @@ source-stamp: ln -sf $${PWD} ${GOPATH}/src/github.com/matttproud/prometheus touch $@ - -gorest: gorest-stamp - -gorest-stamp: go source - $(GO_GET) code.google.com/p/gorest - touch $@ - clean: -rm *-stamp -rm -rf "$(OVERLAY_ROOT)" @@ -155,5 +148,4 @@ clean: -rm protobuf-$(PROTOCOL_BUFFERS_VERSION).tar.bz2 -.PHONY: all bison build-dependencies cc clean go goprotobuf gorest leveldb levigo mercurial overlay preparation protoc rsync source test wget - +.PHONY: all bison build-dependencies cc clean go goprotobuf leveldb levigo mercurial overlay preparation protoc rsync source test wget diff --git a/main.go b/main.go index 490995895..cf7c36fc1 100644 --- a/main.go +++ b/main.go @@ -14,17 +14,22 @@ package main import ( - "code.google.com/p/gorest" "github.com/matttproud/prometheus/storage/metric/leveldb" - "net/http" + "log" + "os" ) func main() { - m, _ := leveldb.NewLevelDBMetricPersistence("/tmp/metrics") - s := &MetricsService{ - persistence: m, + m, err := leveldb.NewLevelDBMetricPersistence("/tmp/metrics") + if err != nil { + log.Print(err) + os.Exit(1) + } + + defer func() { + m.Close() + }() + + for { } - gorest.RegisterService(s) - http.Handle("/", gorest.Handle()) - http.ListenAndServe(":8787", nil) } diff --git a/model/dto.go b/model/dto.go index ffe62ddb8..80db6806b 100644 --- a/model/dto.go +++ b/model/dto.go @@ -24,10 +24,10 @@ import ( ) func SampleToMetricDTO(s *Sample) *dto.Metric { - labelLength := len(s.Labels) + labelLength := len(s.Metric) labelNames := make([]string, 0, labelLength) - for labelName := range s.Labels { + for labelName := range s.Metric { labelNames = append(labelNames, string(labelName)) } @@ -36,7 +36,7 @@ func SampleToMetricDTO(s *Sample) *dto.Metric { labelSets := make([]*dto.LabelPair, 0, labelLength) for _, labelName := range labelNames { - labelValue := s.Labels[LabelName(labelName)] + labelValue := s.Metric[LabelName(labelName)] labelPair := &dto.LabelPair{ Name: proto.String(string(labelName)), Value: proto.String(string(labelValue)), diff --git a/model/metric.go b/model/metric.go index d92cd46ef..277a46b0d 100644 --- a/model/metric.go +++ b/model/metric.go @@ -46,7 +46,7 @@ type Metric map[LabelName]LabelValue type SampleValue float32 type Sample struct { - Labels LabelSet + Metric Metric Value SampleValue Timestamp time.Time } diff --git a/service.go b/service.go deleted file mode 100644 index ab42dd935..000000000 --- a/service.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2012 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 main - -import ( - "code.google.com/p/gorest" - "github.com/matttproud/prometheus/model" - "github.com/matttproud/prometheus/storage/metric/leveldb" -) - -type MetricsService struct { - gorest.RestService `root:"/" consumes:"application/json" produces:"application/json"` - - persistence *leveldb.LevelDBMetricPersistence - - listLabels gorest.EndPoint `method:"GET" path:"/labels/" output:"[]string"` - listLabelPairs gorest.EndPoint `method:"GET" path:"/label-pairs/" output:"[]model.LabelPairs"` - listMetrics gorest.EndPoint `method:"GET" path:"/metrics/" output:"[]model.LabelPairs"` - - appendSample gorest.EndPoint `method:"POST" path:"/metrics/" postdata:"model.Sample"` -} - -func (m MetricsService) ListLabels() []string { - labels, labelsError := m.persistence.GetAllLabelNames() - - if labelsError != nil { - m.ResponseBuilder().SetResponseCode(500) - } - - return labels -} - -func (m MetricsService) ListLabelPairs() []model.LabelSet { - labelSets, labelPairsError := m.persistence.GetAllLabelPairs() - - if labelPairsError != nil { - m.ResponseBuilder().SetResponseCode(500) - } - - return labelSets -} - -func (m MetricsService) ListMetrics() []model.LabelSet { - metrics, metricsError := m.persistence.GetAllMetrics() - - if metricsError != nil { - m.ResponseBuilder().SetResponseCode(500) - } - - return metrics -} - -func (m MetricsService) AppendSample(s model.Sample) { - responseBuilder := m.ResponseBuilder() - if appendError := m.persistence.AppendSample(&s); appendError == nil { - responseBuilder.SetResponseCode(200) - return - } - - responseBuilder.SetResponseCode(500) -} diff --git a/storage/metric/interface.go b/storage/metric/interface.go index 719112a67..5b16be19b 100644 --- a/storage/metric/interface.go +++ b/storage/metric/interface.go @@ -43,8 +43,6 @@ type MetricPersistence interface { // // BEGIN QUERY PRIMITIVES // - // GetMetricForFingerprint() - // GetMetricWatermarks(metrics ...) (watermarks ...) // GetMetricValuesForIntervals(metric, interval) (values ...) // GetMetricValueLast() // // END QUERY PRIMITIVES diff --git a/storage/metric/leveldb/leveldb_test.go b/storage/metric/leveldb/leveldb_test.go index 2bef4b5c2..f8c4a10d8 100644 --- a/storage/metric/leveldb/leveldb_test.go +++ b/storage/metric/leveldb/leveldb_test.go @@ -213,12 +213,12 @@ var testAppendSampleAsPureSparseAppend = func(t tester) { appendSample := func(x int) bool { v := model.SampleValue(x) t := time.Unix(int64(x), int64(x)) - l := model.LabelSet{model.LabelName(x): model.LabelValue(x)} + l := model.Metric{model.LabelName(x): model.LabelValue(x)} sample := &model.Sample{ Value: v, Timestamp: t, - Labels: l, + Metric: l, } appendErr := persistence.AppendSample(sample) @@ -259,12 +259,12 @@ var testAppendSampleAsSparseAppendWithReads func(t tester) = func(t tester) { appendSample := func(x int) bool { v := model.SampleValue(x) t := time.Unix(int64(x), int64(x)) - l := model.LabelSet{model.LabelName(x): model.LabelValue(x)} + l := model.Metric{model.LabelName(x): model.LabelValue(x)} sample := &model.Sample{ Value: v, Timestamp: t, - Labels: l, + Metric: l, } appendErr := persistence.AppendSample(sample) @@ -367,7 +367,7 @@ func TestAppendSampleAsPureSingleEntityAppend(t *testing.T) { sample := &model.Sample{ Value: model.SampleValue(float32(x)), Timestamp: time.Unix(int64(x), 0), - Labels: model.LabelSet{"name": "my_metric"}, + Metric: model.Metric{"name": "my_metric"}, } appendErr := persistence.AppendSample(sample) @@ -412,24 +412,24 @@ func TestStochastic(t *testing.T) { for metricIndex := 0; metricIndex < numberOfMetrics; metricIndex++ { sample := &model.Sample{ - Labels: model.LabelSet{}, + Metric: model.Metric{}, } v := model.LabelValue(fmt.Sprintf("metric_index_%d", metricIndex)) - sample.Labels["name"] = v + sample.Metric["name"] = v for sharedLabelIndex := 0; sharedLabelIndex < numberOfSharedLabels; sharedLabelIndex++ { l := model.LabelName(fmt.Sprintf("shared_label_%d", sharedLabelIndex)) v := model.LabelValue(fmt.Sprintf("label_%d", sharedLabelIndex)) - sample.Labels[l] = v + sample.Metric[l] = v } for unsharedLabelIndex := 0; unsharedLabelIndex < numberOfUnsharedLabels; unsharedLabelIndex++ { l := model.LabelName(fmt.Sprintf("metric_index_%d_private_label_%d", metricIndex, unsharedLabelIndex)) v := model.LabelValue(fmt.Sprintf("private_label_%d", unsharedLabelIndex)) - sample.Labels[l] = v + sample.Metric[l] = v } timestamps := make(map[int64]bool) @@ -691,7 +691,7 @@ func TestGetFingerprintsForLabelSet(t *testing.T) { appendErr := persistence.AppendSample(&model.Sample{ Value: model.SampleValue(0), Timestamp: time.Unix(0, 0), - Labels: model.LabelSet{ + Metric: model.Metric{ "name": "my_metric", "request_type": "your_mom", }, @@ -704,7 +704,7 @@ func TestGetFingerprintsForLabelSet(t *testing.T) { appendErr = persistence.AppendSample(&model.Sample{ Value: model.SampleValue(0), Timestamp: time.Unix(int64(0), 0), - Labels: model.LabelSet{ + Metric: model.Metric{ "name": "my_metric", "request_type": "your_dad", }, @@ -769,7 +769,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) { appendErr := persistence.AppendSample(&model.Sample{ Value: model.SampleValue(0), Timestamp: time.Unix(0, 0), - Labels: model.LabelSet{ + Metric: model.Metric{ "name": "my_metric", "request_type": "your_mom", "language": "english", @@ -783,7 +783,7 @@ func TestGetFingerprintsForLabelName(t *testing.T) { appendErr = persistence.AppendSample(&model.Sample{ Value: model.SampleValue(0), Timestamp: time.Unix(int64(0), 0), - Labels: model.LabelSet{ + Metric: model.Metric{ "name": "my_metric", "request_type": "your_dad", "sprache": "deutsch", @@ -857,7 +857,7 @@ func TestGetMetricForFingerprint(t *testing.T) { appendErr := persistence.AppendSample(&model.Sample{ Value: model.SampleValue(0), Timestamp: time.Unix(0, 0), - Labels: model.LabelSet{ + Metric: model.Metric{ "request_type": "your_mom", }, }) @@ -869,7 +869,7 @@ func TestGetMetricForFingerprint(t *testing.T) { appendErr = persistence.AppendSample(&model.Sample{ Value: model.SampleValue(0), Timestamp: time.Unix(int64(0), 0), - Labels: model.LabelSet{ + Metric: model.Metric{ "request_type": "your_dad", "one-off": "value", },