Skip to content

Commit

Permalink
roachtest: add sample period and source to ts_util
Browse files Browse the repository at this point in the history
Previously, the utility functions for retrieving stats from the
timeseries database in roachtest wouldn't allow specifying a sample
period nor sources. This commit enhances ts_util.go to enable specifying
a sample period via `getMetricsWithSamplePeriod` and updates the
`tsQuery` to have a source field - which is applied on queries.

Release note: None
  • Loading branch information
kvoli committed Jun 27, 2023
1 parent 1a1b737 commit 20e2332
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/cmd/roachtest/tests/ts_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ const (
rate
)

// defaultSamplePeriod is the default sampling period for getMetrics.
const defaultSamplePeriod = time.Minute

type tsQuery struct {
name string
queryType tsQueryType
sources []string
}

func mustGetMetrics(
Expand All @@ -55,6 +59,12 @@ func mustGetMetrics(

func getMetrics(
adminURL string, start, end time.Time, tsQueries []tsQuery,
) (tspb.TimeSeriesQueryResponse, error) {
return getMetricsWithSamplePeriod(adminURL, start, end, defaultSamplePeriod, tsQueries)
}

func getMetricsWithSamplePeriod(
adminURL string, start, end time.Time, samplePeriod time.Duration, tsQueries []tsQuery,
) (tspb.TimeSeriesQueryResponse, error) {
url := "http://" + adminURL + "/ts/query"
queries := make([]tspb.Query, len(tsQueries))
Expand All @@ -65,13 +75,15 @@ func getMetrics(
Name: tsQueries[i].name,
Downsampler: tspb.TimeSeriesQueryAggregator_AVG.Enum(),
SourceAggregator: tspb.TimeSeriesQueryAggregator_SUM.Enum(),
Sources: tsQueries[i].sources,
}
case rate:
queries[i] = tspb.Query{
Name: tsQueries[i].name,
Downsampler: tspb.TimeSeriesQueryAggregator_AVG.Enum(),
SourceAggregator: tspb.TimeSeriesQueryAggregator_SUM.Enum(),
Derivative: tspb.TimeSeriesQueryDerivative_NON_NEGATIVE_DERIVATIVE.Enum(),
Sources: tsQueries[i].sources,
}
default:
panic("unexpected")
Expand All @@ -83,7 +95,7 @@ func getMetrics(
// Ask for one minute intervals. We can't just ask for the whole hour
// because the time series query system does not support downsampling
// offsets.
SampleNanos: (1 * time.Minute).Nanoseconds(),
SampleNanos: samplePeriod.Nanoseconds(),
Queries: queries,
}
var response tspb.TimeSeriesQueryResponse
Expand Down

0 comments on commit 20e2332

Please sign in to comment.