|
|
|
@ -27,138 +27,91 @@ import (
|
|
|
|
|
func testProcessor001Process(t test.Tester) { |
|
|
|
|
var scenarios = []struct { |
|
|
|
|
in string |
|
|
|
|
out []Result |
|
|
|
|
out model.Samples |
|
|
|
|
err error |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
err: fmt.Errorf("unexpected end of JSON input"), |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
in: "[{\"baseLabels\":{\"name\":\"rpc_calls_total\"},\"docstring\":\"RPC calls.\",\"metric\":{\"type\":\"counter\",\"value\":[{\"labels\":{\"service\":\"zed\"},\"value\":25},{\"labels\":{\"service\":\"bar\"},\"value\":25},{\"labels\":{\"service\":\"foo\"},\"value\":25}]}},{\"baseLabels\":{\"name\":\"rpc_latency_microseconds\"},\"docstring\":\"RPC latency.\",\"metric\":{\"type\":\"histogram\",\"value\":[{\"labels\":{\"service\":\"foo\"},\"value\":{\"0.010000\":15.890724674774395,\"0.050000\":15.890724674774395,\"0.500000\":84.63044031436561,\"0.900000\":160.21100853053224,\"0.990000\":172.49828748957728}},{\"labels\":{\"service\":\"zed\"},\"value\":{\"0.010000\":0.0459814091918713,\"0.050000\":0.0459814091918713,\"0.500000\":0.6120456642749681,\"0.900000\":1.355915069887731,\"0.990000\":1.772733213161236}},{\"labels\":{\"service\":\"bar\"},\"value\":{\"0.010000\":78.48563317257356,\"0.050000\":78.48563317257356,\"0.500000\":97.31798360385088,\"0.900000\":109.89202084295582,\"0.990000\":109.99626121011262}}]}}]", |
|
|
|
|
out: []Result{ |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
Metric: model.Metric{"service": "zed", model.MetricNameLabel: "rpc_calls_total"}, |
|
|
|
|
Value: 25, |
|
|
|
|
}, |
|
|
|
|
in: `[{"baseLabels":{"name":"rpc_calls_total"},"docstring":"RPC calls.","metric":{"type":"counter","value":[{"labels":{"service":"zed"},"value":25},{"labels":{"service":"bar"},"value":25},{"labels":{"service":"foo"},"value":25}]}},{"baseLabels":{"name":"rpc_latency_microseconds"},"docstring":"RPC latency.","metric":{"type":"histogram","value":[{"labels":{"service":"foo"},"value":{"0.010000":15.890724674774395,"0.050000":15.890724674774395,"0.500000":84.63044031436561,"0.900000":160.21100853053224,"0.990000":172.49828748957728}},{"labels":{"service":"zed"},"value":{"0.010000":0.0459814091918713,"0.050000":0.0459814091918713,"0.500000":0.6120456642749681,"0.900000":1.355915069887731,"0.990000":1.772733213161236}},{"labels":{"service":"bar"},"value":{"0.010000":78.48563317257356,"0.050000":78.48563317257356,"0.500000":97.31798360385088,"0.900000":109.89202084295582,"0.990000":109.99626121011262}}]}}]`, |
|
|
|
|
out: model.Samples{ |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"service": "zed", model.MetricNameLabel: "rpc_calls_total"}, |
|
|
|
|
Value: 25, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
Metric: model.Metric{"service": "bar", model.MetricNameLabel: "rpc_calls_total"}, |
|
|
|
|
Value: 25, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"service": "bar", model.MetricNameLabel: "rpc_calls_total"}, |
|
|
|
|
Value: 25, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"service": "foo", model.MetricNameLabel: "rpc_calls_total"}, |
|
|
|
|
Value: 25, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"service": "foo", model.MetricNameLabel: "rpc_calls_total"}, |
|
|
|
|
Value: 25, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 0.0459814091918713, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 0.0459814091918713, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 78.48563317257356, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 78.48563317257356, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 15.890724674774395, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.010000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 15.890724674774395, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 0.0459814091918713, |
|
|
|
|
}, |
|
|
|
|
Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 0.0459814091918713, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 78.48563317257356, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 78.48563317257356, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 15.890724674774395, |
|
|
|
|
}, |
|
|
|
|
Metric: model.Metric{"percentile": "0.050000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 15.890724674774395, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 0.6120456642749681, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 0.6120456642749681, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 97.31798360385088, |
|
|
|
|
}, |
|
|
|
|
Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 97.31798360385088, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 84.63044031436561, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.500000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 84.63044031436561, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 1.355915069887731, |
|
|
|
|
}, |
|
|
|
|
Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 1.355915069887731, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 109.89202084295582, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 109.89202084295582, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 160.21100853053224, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.900000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 160.21100853053224, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 1.772733213161236, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "zed"}, |
|
|
|
|
Value: 1.772733213161236, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 109.99626121011262, |
|
|
|
|
}, |
|
|
|
|
Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "bar"}, |
|
|
|
|
Value: 109.99626121011262, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Sample: model.Sample{ |
|
|
|
|
|
|
|
|
|
Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 172.49828748957728, |
|
|
|
|
}, |
|
|
|
|
model.Sample{ |
|
|
|
|
Metric: model.Metric{"percentile": "0.990000", model.MetricNameLabel: "rpc_latency_microseconds", "service": "foo"}, |
|
|
|
|
Value: 172.49828748957728, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
@ -179,18 +132,14 @@ func testProcessor001Process(t test.Tester) {
|
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if scenario.err != nil && err != nil { |
|
|
|
|
if scenario.err.Error() != err.Error() { |
|
|
|
|
t.Errorf("%d. expected err of %s, got %s", i, scenario.err, err) |
|
|
|
|
} |
|
|
|
|
} else if scenario.err != err { |
|
|
|
|
t.Errorf("%d. expected err of %s, got %s", i, scenario.err, err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
delivered := make([]Result, 0) |
|
|
|
|
delivered := model.Samples{} |
|
|
|
|
|
|
|
|
|
for len(inputChannel) != 0 { |
|
|
|
|
delivered = append(delivered, <-inputChannel) |
|
|
|
|
result := <-inputChannel |
|
|
|
|
if result.Err != nil { |
|
|
|
|
t.Fatalf("%d. expected no error, got: %s", i, result.Err) |
|
|
|
|
} |
|
|
|
|
delivered = append(delivered, result.Samples...) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(delivered) != len(scenario.out) { |
|
|
|
@ -209,24 +158,20 @@ func testProcessor001Process(t test.Tester) {
|
|
|
|
|
|
|
|
|
|
found := false |
|
|
|
|
for element := expectedElements.Front(); element != nil && found == false; element = element.Next() { |
|
|
|
|
candidate := element.Value.(Result) |
|
|
|
|
|
|
|
|
|
if !test.ErrorEqual(candidate.Err, actual.Err) { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
candidate := element.Value.(model.Sample) |
|
|
|
|
|
|
|
|
|
if candidate.Sample.Value != actual.Sample.Value { |
|
|
|
|
if candidate.Value != actual.Value { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(candidate.Sample.Metric) != len(actual.Sample.Metric) { |
|
|
|
|
if len(candidate.Metric) != len(actual.Metric) { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
labelsMatch := false |
|
|
|
|
|
|
|
|
|
for key, value := range candidate.Sample.Metric { |
|
|
|
|
actualValue, ok := actual.Sample.Metric[key] |
|
|
|
|
for key, value := range candidate.Metric { |
|
|
|
|
actualValue, ok := actual.Metric[key] |
|
|
|
|
if !ok { |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
@ -246,7 +191,7 @@ func testProcessor001Process(t test.Tester) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if !found { |
|
|
|
|
t.Errorf("%d.%d. expected to find %s among candidate, absent", i, j, actual.Sample) |
|
|
|
|
t.Errorf("%d.%d. expected to find %s among candidate, absent", i, j, actual) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|