mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
api/v1: fix tests, restore series queries
This commit is contained in:
parent
e94b0899ee
commit
28f547bcc7
|
@ -324,6 +324,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *EvalStmt) (
|
||||||
Seriess[0] = ss
|
Seriess[0] = ss
|
||||||
}
|
}
|
||||||
ss.Points = append(ss.Points, Point(v))
|
ss.Points = append(ss.Points, Point(v))
|
||||||
|
Seriess[0] = ss
|
||||||
case Vector:
|
case Vector:
|
||||||
for _, sample := range v {
|
for _, sample := range v {
|
||||||
h := sample.Metric.Hash()
|
h := sample.Metric.Hash()
|
||||||
|
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/pkg/labels"
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
|
"github.com/prometheus/prometheus/pkg/timestamp"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/retrieval"
|
"github.com/prometheus/prometheus/retrieval"
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
|
@ -294,26 +295,28 @@ func (api *API) series(r *http.Request) (interface{}, *apiError) {
|
||||||
matcherSets = append(matcherSets, matchers)
|
matcherSets = append(matcherSets, matchers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(fabxc): temporarily disbaled.
|
q, err := api.Storage.Querier(timestamp.FromTime(start), timestamp.FromTime(end))
|
||||||
_, _ = start, end
|
if err != nil {
|
||||||
panic("disabled")
|
return nil, &apiError{errorExec, err}
|
||||||
|
}
|
||||||
|
defer q.Close()
|
||||||
|
|
||||||
// q, err := api.Storage.Querier()
|
// TODO(fabxc): expose merge functionality in storage interface.
|
||||||
// if err != nil {
|
// We just concatenate results for all sets of matchers, which may produce
|
||||||
// return nil, &apiError{errorExec, err}
|
// duplicated results.
|
||||||
// }
|
metrics := []labels.Labels{}
|
||||||
// defer q.Close()
|
|
||||||
|
|
||||||
// res, err := q.MetricsForLabelMatchers(api.context(r), start, end, matcherSets...)
|
for _, mset := range matcherSets {
|
||||||
// if err != nil {
|
series := q.Select(mset...)
|
||||||
// return nil, &apiError{errorExec, err}
|
for series.Next() {
|
||||||
// }
|
metrics = append(metrics, series.Series().Labels())
|
||||||
|
}
|
||||||
|
if series.Err() != nil {
|
||||||
|
return nil, &apiError{errorExec, series.Err()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// metrics := make([]model.Metric, 0, len(res))
|
return metrics, nil
|
||||||
// for _, met := range res {
|
|
||||||
// metrics = append(metrics, met.Metric)
|
|
||||||
// }
|
|
||||||
// return metrics, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) dropSeries(r *http.Request) (interface{}, *apiError) {
|
func (api *API) dropSeries(r *http.Request) (interface{}, *apiError) {
|
||||||
|
|
|
@ -29,6 +29,8 @@ import (
|
||||||
"github.com/prometheus/common/route"
|
"github.com/prometheus/common/route"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
|
"github.com/prometheus/prometheus/pkg/timestamp"
|
||||||
"github.com/prometheus/prometheus/promql"
|
"github.com/prometheus/prometheus/promql"
|
||||||
"github.com/prometheus/prometheus/retrieval"
|
"github.com/prometheus/prometheus/retrieval"
|
||||||
)
|
)
|
||||||
|
@ -55,17 +57,17 @@ func TestEndpoints(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
now := model.Now()
|
now := time.Now()
|
||||||
|
|
||||||
tr := targetRetrieverFunc(func() []retrieval.Target {
|
tr := targetRetrieverFunc(func() []retrieval.Target {
|
||||||
return []retrieval.Target{
|
return []retrieval.Target{
|
||||||
*retrieval.NewTarget(
|
*retrieval.NewTarget(
|
||||||
model.LabelSet{
|
labels.FromMap(map[string]string{
|
||||||
model.SchemeLabel: "http",
|
model.SchemeLabel: "http",
|
||||||
model.AddressLabel: "example.com:8080",
|
model.AddressLabel: "example.com:8080",
|
||||||
model.MetricsPathLabel: "/metrics",
|
model.MetricsPathLabel: "/metrics",
|
||||||
},
|
}),
|
||||||
model.LabelSet{},
|
nil,
|
||||||
url.Values{},
|
url.Values{},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
@ -75,10 +77,11 @@ func TestEndpoints(t *testing.T) {
|
||||||
Storage: suite.Storage(),
|
Storage: suite.Storage(),
|
||||||
QueryEngine: suite.QueryEngine(),
|
QueryEngine: suite.QueryEngine(),
|
||||||
targetRetriever: tr,
|
targetRetriever: tr,
|
||||||
now: func() model.Time { return now },
|
now: func() time.Time { return now },
|
||||||
}
|
}
|
||||||
|
|
||||||
start := model.Time(0)
|
start := time.Unix(0, 0)
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
endpoint apiFunc
|
endpoint apiFunc
|
||||||
params map[string]string
|
params map[string]string
|
||||||
|
@ -90,13 +93,13 @@ func TestEndpoints(t *testing.T) {
|
||||||
endpoint: api.query,
|
endpoint: api.query,
|
||||||
query: url.Values{
|
query: url.Values{
|
||||||
"query": []string{"2"},
|
"query": []string{"2"},
|
||||||
"time": []string{"123.3"},
|
"time": []string{"123.4"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &queryData{
|
||||||
ResultType: model.ValScalar,
|
ResultType: promql.ValueTypeScalar,
|
||||||
Result: &model.Scalar{
|
Result: promql.Scalar{
|
||||||
Value: 2,
|
V: 2,
|
||||||
Timestamp: start.Add(123*time.Second + 300*time.Millisecond),
|
T: timestamp.FromTime(start.Add(123*time.Second + 400*time.Millisecond)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -107,10 +110,10 @@ func TestEndpoints(t *testing.T) {
|
||||||
"time": []string{"1970-01-01T00:02:03Z"},
|
"time": []string{"1970-01-01T00:02:03Z"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &queryData{
|
||||||
ResultType: model.ValScalar,
|
ResultType: promql.ValueTypeScalar,
|
||||||
Result: &model.Scalar{
|
Result: promql.Scalar{
|
||||||
Value: 0.333,
|
V: 0.333,
|
||||||
Timestamp: start.Add(123 * time.Second),
|
T: timestamp.FromTime(start.Add(123 * time.Second)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -121,10 +124,10 @@ func TestEndpoints(t *testing.T) {
|
||||||
"time": []string{"1970-01-01T01:02:03+01:00"},
|
"time": []string{"1970-01-01T01:02:03+01:00"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &queryData{
|
||||||
ResultType: model.ValScalar,
|
ResultType: promql.ValueTypeScalar,
|
||||||
Result: &model.Scalar{
|
Result: promql.Scalar{
|
||||||
Value: 0.333,
|
V: 0.333,
|
||||||
Timestamp: start.Add(123 * time.Second),
|
T: timestamp.FromTime(start.Add(123 * time.Second)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -134,10 +137,10 @@ func TestEndpoints(t *testing.T) {
|
||||||
"query": []string{"0.333"},
|
"query": []string{"0.333"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &queryData{
|
||||||
ResultType: model.ValScalar,
|
ResultType: promql.ValueTypeScalar,
|
||||||
Result: &model.Scalar{
|
Result: promql.Scalar{
|
||||||
Value: 0.333,
|
V: 0.333,
|
||||||
Timestamp: now,
|
T: timestamp.FromTime(now),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -150,15 +153,15 @@ func TestEndpoints(t *testing.T) {
|
||||||
"step": []string{"1"},
|
"step": []string{"1"},
|
||||||
},
|
},
|
||||||
response: &queryData{
|
response: &queryData{
|
||||||
ResultType: model.ValMatrix,
|
ResultType: promql.ValueTypeMatrix,
|
||||||
Result: model.Matrix{
|
Result: promql.Matrix{
|
||||||
&model.SampleStream{
|
promql.Series{
|
||||||
Values: []model.SamplePair{
|
Points: []promql.Point{
|
||||||
{Value: 0, Timestamp: start},
|
{V: 0, T: timestamp.FromTime(start)},
|
||||||
{Value: 1, Timestamp: start.Add(1 * time.Second)},
|
{V: 1, T: timestamp.FromTime(start.Add(1 * time.Second))},
|
||||||
{Value: 2, Timestamp: start.Add(2 * time.Second)},
|
{V: 2, T: timestamp.FromTime(start.Add(2 * time.Second))},
|
||||||
},
|
},
|
||||||
Metric: model.Metric{},
|
Metric: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -237,7 +240,7 @@ func TestEndpoints(t *testing.T) {
|
||||||
params: map[string]string{
|
params: map[string]string{
|
||||||
"name": "__name__",
|
"name": "__name__",
|
||||||
},
|
},
|
||||||
response: model.LabelValues{
|
response: []string{
|
||||||
"test_metric1",
|
"test_metric1",
|
||||||
"test_metric2",
|
"test_metric2",
|
||||||
},
|
},
|
||||||
|
@ -247,7 +250,7 @@ func TestEndpoints(t *testing.T) {
|
||||||
params: map[string]string{
|
params: map[string]string{
|
||||||
"name": "foo",
|
"name": "foo",
|
||||||
},
|
},
|
||||||
response: model.LabelValues{
|
response: []string{
|
||||||
"bar",
|
"bar",
|
||||||
"boo",
|
"boo",
|
||||||
},
|
},
|
||||||
|
@ -265,11 +268,8 @@ func TestEndpoints(t *testing.T) {
|
||||||
query: url.Values{
|
query: url.Values{
|
||||||
"match[]": []string{`test_metric2`},
|
"match[]": []string{`test_metric2`},
|
||||||
},
|
},
|
||||||
response: []model.Metric{
|
response: []labels.Labels{
|
||||||
{
|
labels.FromStrings("__name__", "test_metric2", "foo", "boo"),
|
||||||
"__name__": "test_metric2",
|
|
||||||
"foo": "boo",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -277,23 +277,18 @@ func TestEndpoints(t *testing.T) {
|
||||||
query: url.Values{
|
query: url.Values{
|
||||||
"match[]": []string{`test_metric1{foo=~".+o"}`},
|
"match[]": []string{`test_metric1{foo=~".+o"}`},
|
||||||
},
|
},
|
||||||
response: []model.Metric{
|
response: []labels.Labels{
|
||||||
{
|
labels.FromStrings("__name__", "test_metric1", "foo", "boo"),
|
||||||
"__name__": "test_metric1",
|
|
||||||
"foo": "boo",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
endpoint: api.series,
|
endpoint: api.series,
|
||||||
query: url.Values{
|
query: url.Values{
|
||||||
"match[]": []string{`test_metric1{foo=~"o$"}`, `test_metric1{foo=~".+o"}`},
|
"match[]": []string{`test_metric1{foo=~".+o$"}`, `test_metric1{foo=~".+o"}`},
|
||||||
},
|
|
||||||
response: []model.Metric{
|
|
||||||
{
|
|
||||||
"__name__": "test_metric1",
|
|
||||||
"foo": "boo",
|
|
||||||
},
|
},
|
||||||
|
response: []labels.Labels{
|
||||||
|
labels.FromStrings("__name__", "test_metric1", "foo", "boo"),
|
||||||
|
labels.FromStrings("__name__", "test_metric1", "foo", "boo"), // TODO(fabxc): see comment in implementation.
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -301,11 +296,8 @@ func TestEndpoints(t *testing.T) {
|
||||||
query: url.Values{
|
query: url.Values{
|
||||||
"match[]": []string{`test_metric1{foo=~".+o"}`, `none`},
|
"match[]": []string{`test_metric1{foo=~".+o"}`, `none`},
|
||||||
},
|
},
|
||||||
response: []model.Metric{
|
response: []labels.Labels{
|
||||||
{
|
labels.FromStrings("__name__", "test_metric1", "foo", "boo"),
|
||||||
"__name__": "test_metric1",
|
|
||||||
"foo": "boo",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Start and end before series starts.
|
// Start and end before series starts.
|
||||||
|
@ -316,7 +308,7 @@ func TestEndpoints(t *testing.T) {
|
||||||
"start": []string{"-2"},
|
"start": []string{"-2"},
|
||||||
"end": []string{"-1"},
|
"end": []string{"-1"},
|
||||||
},
|
},
|
||||||
response: []model.Metric{},
|
response: []labels.Labels{},
|
||||||
},
|
},
|
||||||
// Start and end after series ends.
|
// Start and end after series ends.
|
||||||
{
|
{
|
||||||
|
@ -326,7 +318,7 @@ func TestEndpoints(t *testing.T) {
|
||||||
"start": []string{"100000"},
|
"start": []string{"100000"},
|
||||||
"end": []string{"100001"},
|
"end": []string{"100001"},
|
||||||
},
|
},
|
||||||
response: []model.Metric{},
|
response: []labels.Labels{},
|
||||||
},
|
},
|
||||||
// Start before series starts, end after series ends.
|
// Start before series starts, end after series ends.
|
||||||
{
|
{
|
||||||
|
@ -336,11 +328,8 @@ func TestEndpoints(t *testing.T) {
|
||||||
"start": []string{"-1"},
|
"start": []string{"-1"},
|
||||||
"end": []string{"100000"},
|
"end": []string{"100000"},
|
||||||
},
|
},
|
||||||
response: []model.Metric{
|
response: []labels.Labels{
|
||||||
{
|
labels.FromStrings("__name__", "test_metric2", "foo", "boo"),
|
||||||
"__name__": "test_metric2",
|
|
||||||
"foo": "boo",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Start and end within series.
|
// Start and end within series.
|
||||||
|
@ -351,11 +340,8 @@ func TestEndpoints(t *testing.T) {
|
||||||
"start": []string{"1"},
|
"start": []string{"1"},
|
||||||
"end": []string{"100"},
|
"end": []string{"100"},
|
||||||
},
|
},
|
||||||
response: []model.Metric{
|
response: []labels.Labels{
|
||||||
{
|
labels.FromStrings("__name__", "test_metric2", "foo", "boo"),
|
||||||
"__name__": "test_metric2",
|
|
||||||
"foo": "boo",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Start within series, end after.
|
// Start within series, end after.
|
||||||
|
@ -366,11 +352,8 @@ func TestEndpoints(t *testing.T) {
|
||||||
"start": []string{"1"},
|
"start": []string{"1"},
|
||||||
"end": []string{"100000"},
|
"end": []string{"100000"},
|
||||||
},
|
},
|
||||||
response: []model.Metric{
|
response: []labels.Labels{
|
||||||
{
|
labels.FromStrings("__name__", "test_metric2", "foo", "boo"),
|
||||||
"__name__": "test_metric2",
|
|
||||||
"foo": "boo",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Start before series, end within series.
|
// Start before series, end within series.
|
||||||
|
@ -381,11 +364,8 @@ func TestEndpoints(t *testing.T) {
|
||||||
"start": []string{"-1"},
|
"start": []string{"-1"},
|
||||||
"end": []string{"1"},
|
"end": []string{"1"},
|
||||||
},
|
},
|
||||||
response: []model.Metric{
|
response: []labels.Labels{
|
||||||
{
|
labels.FromStrings("__name__", "test_metric2", "foo", "boo"),
|
||||||
"__name__": "test_metric2",
|
|
||||||
"foo": "boo",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// Missing match[] query params in series requests.
|
// Missing match[] query params in series requests.
|
||||||
|
@ -399,45 +379,45 @@ func TestEndpoints(t *testing.T) {
|
||||||
},
|
},
|
||||||
// The following tests delete time series from the test storage. They
|
// The following tests delete time series from the test storage. They
|
||||||
// must remain at the end and are fixed in their order.
|
// must remain at the end and are fixed in their order.
|
||||||
{
|
// {
|
||||||
endpoint: api.dropSeries,
|
// endpoint: api.dropSeries,
|
||||||
query: url.Values{
|
// query: url.Values{
|
||||||
"match[]": []string{`test_metric1{foo=~".+o"}`},
|
// "match[]": []string{`test_metric1{foo=~".+o"}`},
|
||||||
},
|
// },
|
||||||
response: struct {
|
// response: struct {
|
||||||
NumDeleted int `json:"numDeleted"`
|
// NumDeleted int `json:"numDeleted"`
|
||||||
}{1},
|
// }{1},
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
endpoint: api.series,
|
// endpoint: api.series,
|
||||||
query: url.Values{
|
// query: url.Values{
|
||||||
"match[]": []string{`test_metric1`},
|
// "match[]": []string{`test_metric1`},
|
||||||
},
|
// },
|
||||||
response: []model.Metric{
|
// response: []model.Metric{
|
||||||
{
|
// {
|
||||||
"__name__": "test_metric1",
|
// "__name__": "test_metric1",
|
||||||
"foo": "bar",
|
// "foo": "bar",
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
}, {
|
// }, {
|
||||||
endpoint: api.dropSeries,
|
// endpoint: api.dropSeries,
|
||||||
query: url.Values{
|
// query: url.Values{
|
||||||
"match[]": []string{`{__name__=~".+"}`},
|
// "match[]": []string{`{__name__=~".+"}`},
|
||||||
},
|
// },
|
||||||
response: struct {
|
// response: struct {
|
||||||
NumDeleted int `json:"numDeleted"`
|
// NumDeleted int `json:"numDeleted"`
|
||||||
}{2},
|
// }{2},
|
||||||
}, {
|
// }, {
|
||||||
endpoint: api.targets,
|
// endpoint: api.targets,
|
||||||
response: []*Target{
|
// response: []*Target{
|
||||||
&Target{
|
// &Target{
|
||||||
DiscoveredLabels: model.LabelSet{},
|
// DiscoveredLabels: nil,
|
||||||
Labels: model.LabelSet{},
|
// Labels: nil,
|
||||||
ScrapeUrl: "http://example.com:8080/metrics",
|
// ScrapeUrl: "http://example.com:8080/metrics",
|
||||||
Health: "unknown",
|
// Health: "unknown",
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
@ -470,8 +450,6 @@ func TestEndpoints(t *testing.T) {
|
||||||
if !reflect.DeepEqual(resp, test.response) {
|
if !reflect.DeepEqual(resp, test.response) {
|
||||||
t.Fatalf("Response does not match, expected:\n%+v\ngot:\n%+v", test.response, resp)
|
t.Fatalf("Response does not match, expected:\n%+v\ngot:\n%+v", test.response, resp)
|
||||||
}
|
}
|
||||||
// Ensure that removed metrics are unindexed before the next request.
|
|
||||||
suite.Storage().WaitForIndexing()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,9 +577,8 @@ func TestParseTime(t *testing.T) {
|
||||||
t.Errorf("Expected error for %q but got none", test.input)
|
t.Errorf("Expected error for %q but got none", test.input)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
res := model.TimeFromUnixNano(test.result.UnixNano())
|
if !test.fail && !ts.Equal(test.result) {
|
||||||
if !test.fail && ts != res {
|
t.Errorf("Expected time %v for input %q but got %v", test.result, test.input, ts)
|
||||||
t.Errorf("Expected time %v for input %q but got %v", res, test.input, ts)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue