Skip to content

Commit

Permalink
Merge pull request kubernetes#2295 from tosi3k/promtime
Browse files Browse the repository at this point in the history
Take full duration into account in Prometheus-based measurements
  • Loading branch information
k8s-ci-robot authored Jul 10, 2023
2 parents 4c08d58 + 1c5e609 commit 1ba68e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"below-threshold-query[1m]": {{Value: model.SampleValue(7)}},
"no-threshold-query[1m]": {{Value: model.SampleValue(120)}},
"placeholder-a[1m] + placeholder-b[1m]": {{Value: model.SampleValue(5)}},
"below-threshold-query[60s]": {{Value: model.SampleValue(7)}},
"no-threshold-query[60s]": {{Value: model.SampleValue(120)}},
"placeholder-a[60s] + placeholder-b[60s]": {{Value: model.SampleValue(5)}},
},
wantDataItems: []measurementutil.DataItem{
{
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"many-samples-query[1m]": {
"many-samples-query[60s]": {
{Value: model.SampleValue(1)},
{Value: model.SampleValue(2)},
},
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"above-threshold-query[1m]": {{Value: model.SampleValue(123)}},
"above-threshold-query[60s]": {{Value: model.SampleValue(123)}},
},
wantErr: "sample above threshold: want: less or equal than 60, got: 123",
wantDataItems: []measurementutil.DataItem{
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"query-perc99[1m]": {
"query-perc99[60s]": {
{
Metric: model.Metric{
model.LabelName("d1"): model.LabelValue("d1-val1"),
Expand All @@ -238,7 +238,7 @@ func TestGather(t *testing.T) {
Value: model.SampleValue(2),
},
},
"query-perc90[1m]": {
"query-perc90[60s]": {
{
Metric: model.Metric{
model.LabelName("d1"): model.LabelValue("d1-val1"),
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"query-perc99[1m]": {
"query-perc99[60s]": {
{
Metric: model.Metric{
model.LabelName("d1"): model.LabelValue("d1-val1"),
Expand Down
5 changes: 1 addition & 4 deletions clusterloader2/pkg/measurement/util/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,5 @@ func (qr *promResponseData) UnmarshalJSON(b []byte) error {

// ToPrometheusTime returns prometheus string representation of given time.
func ToPrometheusTime(t time.Duration) string {
if t < time.Minute {
return fmt.Sprintf("%ds", int64(t)/int64(time.Second))
}
return fmt.Sprintf("%dm", int64(t)/int64(time.Minute))
return fmt.Sprintf("%ds", int64(t)/int64(time.Second))
}

0 comments on commit 1ba68e4

Please sign in to comment.