This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for benchmarking new series creation.
Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
- Loading branch information
1 parent
23655d9
commit e7f16a8
Showing
2 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// This file and its contents are licensed under the Apache License 2.0. | ||
// Please see the included NOTICE for copyright information and | ||
// LICENSE for a copy of the license. | ||
|
||
package testsupport | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
|
||
"github.com/timescale/promscale/pkg/prompb" | ||
) | ||
|
||
type seriesGen struct { | ||
ts []prompb.TimeSeries | ||
} | ||
|
||
const ( | ||
labelKeyPrefix = "test_k_" | ||
labelValuePrefix = "test_v_" | ||
metricNamePrefix = "test_metric_" | ||
) | ||
|
||
var samples = []prompb.Sample{{Timestamp: 1, Value: 1}} | ||
|
||
// NewSeriesGenerator generates distinct timeseries equal to numMetrics * numSeriesPerMetric, such that | ||
// each timeseries has `labels` count of labels. The label keys are common across the series, but their | ||
// values are random, thereby creating a new series. | ||
func NewSeriesGenerator(numMetrics, numSeriesPerMetric, labels int) (*seriesGen, error) { | ||
if labels < 2 { | ||
return nil, fmt.Errorf("minLabels cannot be less than 2") | ||
} | ||
totalSeries := numMetrics * numSeriesPerMetric | ||
ts := make([]prompb.TimeSeries, 0, totalSeries) | ||
|
||
labels -= 1 // Since 1 label will be occupied by __name__ | ||
labelKeys := make([]string, labels) | ||
for i := 0; i < labels; i++ { | ||
labelKeys[i] = fmt.Sprintf("%s%d", labelKeyPrefix, i) | ||
} | ||
|
||
for i := 0; i < numMetrics; i++ { | ||
metricName := randomText(metricNamePrefix) | ||
metric := prompb.Label{Name: "__name__", Value: metricName} | ||
|
||
for j := 0; j < numSeriesPerMetric; j++ { | ||
serie := []prompb.Label{metric} | ||
|
||
for k := 0; k < labels; k++ { | ||
// The keys remain the same across the series, but the values change, everytime creating a new series. | ||
serie = append(serie, prompb.Label{Name: labelKeys[k], Value: randomText(labelValuePrefix)}) | ||
} | ||
ts = append(ts, prompb.TimeSeries{ | ||
Labels: serie, | ||
Samples: samples, | ||
}) | ||
} | ||
} | ||
return &seriesGen{ts}, nil | ||
} | ||
|
||
func (s *seriesGen) GetTimeseries() []prompb.TimeSeries { | ||
return s.ts | ||
} | ||
|
||
func randomText(prefix string) string { | ||
suffix := rand.Int() // #nosec | ||
return fmt.Sprintf("%s%d", prefix, suffix) | ||
} |