コード例 #1
0
func AppendRepeatingValuesTests(p MetricPersistence, t test.Tester) {
	metric := model.Metric{
		model.MetricNameLabel: "errors_total",
		"controller":          "foo",
		"operation":           "bar",
	}

	increments := 10
	repetitions := 500

	for i := 0; i < increments; i++ {
		for j := 0; j < repetitions; j++ {
			time := time.Time{}.Add(time.Duration(i) * time.Hour).Add(time.Duration(j) * time.Second)
			testAppendSample(p, model.Sample{
				Value:     model.SampleValue(i),
				Timestamp: time,
				Metric:    metric,
			}, t)
		}
	}

	if true {
		// XXX: Purely a benchmark.
		return
	}

	labelSet := model.LabelSet{
		model.MetricNameLabel: "errors_total",
		"controller":          "foo",
		"operation":           "bar",
	}

	for i := 0; i < increments; i++ {
		for j := 0; j < repetitions; j++ {
			fingerprints, err := p.GetFingerprintsForLabelSet(labelSet)
			if err != nil {
				t.Fatal(err)
			}
			if len(fingerprints) != 1 {
				t.Fatalf("expected %d fingerprints, got %d", 1, len(fingerprints))
			}

			time := time.Time{}.Add(time.Duration(i) * time.Hour).Add(time.Duration(j) * time.Second)
			sample, err := p.GetValueAtTime(fingerprints[0], time, StalenessPolicy{})
			if err != nil {
				t.Fatal(err)
			}
			if sample == nil {
				t.Fatal("expected non-nil sample.")
			}

			expected := model.SampleValue(i)

			if sample.Value != expected {
				t.Fatalf("expected %d value, got %d", expected, sample.Value)
			}
		}
	}
}