mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-11 08:04:04 -08:00
a2e4439086
Allows to use graphite over tcp or udp. Metrics labels and values are used to construct a valid Graphite path in a way that will allow us to eventually read them back and reconstruct the metrics. For example, this metric: model.Metric{ model.MetricNameLabel: "test:metric", "testlabel": "test:value", "testlabel2": "test:value", ) Will become: test:metric.testlabel=test:value.testlabel2=test:value escape.go takes care of escaping values to match Graphite character set, it basically uses percent-encoding as a fallback wich will work pretty will in the graphite/grafana world. The remote storage module also has an optional 'prefix' parameter to prefix all metrics with a path (for example, 'prometheus.'). Graphite URLs are simply in the form tcp://host:port or udp://host:port.
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
// Copyright 2015 The Prometheus Authors
|
|
// 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 graphite
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prometheus/common/model"
|
|
)
|
|
|
|
var (
|
|
metric = model.Metric{
|
|
model.MetricNameLabel: "test:metric",
|
|
"testlabel": "test:value",
|
|
"many_chars": "abc!ABC:012-3!45ö67~89./(){},=.\"\\",
|
|
}
|
|
)
|
|
|
|
func TestEscape(t *testing.T) {
|
|
// Can we correctly keep and escape valid chars.
|
|
value := "abzABZ019(){},'\"\\"
|
|
expected := "abzABZ019\\(\\)\\{\\}\\,\\'\\\"\\\\"
|
|
actual := escape(model.LabelValue(value))
|
|
if expected != actual {
|
|
t.Errorf("Expected %s, got %s", expected, actual)
|
|
}
|
|
|
|
// Test percent-encoding.
|
|
value = "é/|_;:%."
|
|
expected = "%C3%A9%2F|_;:%25%2E"
|
|
actual = escape(model.LabelValue(value))
|
|
if expected != actual {
|
|
t.Errorf("Expected %s, got %s", expected, actual)
|
|
}
|
|
}
|
|
|
|
func TestPathFromMetric(t *testing.T) {
|
|
expected := ("prefix." +
|
|
"test:metric" +
|
|
".many_chars=abc!ABC:012-3!45%C3%B667~89%2E%2F\\(\\)\\{\\}\\,%3D%2E\\\"\\\\" +
|
|
".testlabel=test:value")
|
|
actual := pathFromMetric(metric, "prefix.")
|
|
if expected != actual {
|
|
t.Errorf("Expected %s, got %s", expected, actual)
|
|
}
|
|
}
|