Skip to content

Commit

Permalink
Metrics view timeseries max msg fix (#3415)
Browse files Browse the repository at this point in the history
Co-authored-by: Egor Ryashin <[email protected]>
  • Loading branch information
egor-ryashin and Egor Ryashin authored Nov 8, 2023
1 parent 0182bda commit 87e67ae
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
8 changes: 7 additions & 1 deletion runtime/queries/metricsview_timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ func (q *MetricsViewTimeSeries) Resolve(ctx context.Context, rt *runtime.Runtime
start = addTo(t, q.TimeGranularity, tz)
}
if q.TimeEnd != nil && nullRecords != nil {
data = addNulls(data, nullRecords, start, q.TimeEnd.AsTime(), q.TimeGranularity, tz)
if start.Equal(zeroTime) && q.TimeStart != nil {
start = q.TimeStart.AsTime()
}

if !start.Equal(zeroTime) {
data = addNulls(data, nullRecords, start, q.TimeEnd.AsTime(), q.TimeGranularity, tz)
}
}

meta := structTypeToMetricsViewColumn(rows.Schema)
Expand Down
49 changes: 49 additions & 0 deletions runtime/server/queries_metrics_timeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,55 @@ func TestServer_Timeseries_1day(t *testing.T) {
require.Equal(t, 2, len(results))
}

func TestServer_Timeseries_1day_no_data(t *testing.T) {
t.Parallel()
server, instanceID := getMetricsTestServer(t, "timeseries")

response, err := server.MetricsViewTimeSeries(testCtx(), &runtimev1.MetricsViewTimeSeriesRequest{
InstanceId: instanceID,
MetricsViewName: "timeseries",
MeasureNames: []string{"max_clicks"},
TimeStart: parseTimeToProtoTimeStamps(t, "2018-01-01T00:00:00Z"),
TimeEnd: parseTimeToProtoTimeStamps(t, "2018-01-03T00:00:00Z"),
TimeGranularity: runtimev1.TimeGrain_TIME_GRAIN_DAY,
})

require.NoError(t, err)
results := response.Data
require.Equal(t, 2, len(results))
require.Equal(t, parseTime(t, "2018-01-01T00:00:00Z"), results[0].Ts.AsTime())
require.Equal(t, parseTime(t, "2018-01-02T00:00:00Z"), results[1].Ts.AsTime())
}

func TestServer_Timeseries_1day_no_data_no_range(t *testing.T) {
t.Parallel()
server, instanceID := getMetricsTestServer(t, "timeseries")

response, err := server.MetricsViewTimeSeries(testCtx(), &runtimev1.MetricsViewTimeSeriesRequest{
InstanceId: instanceID,
MetricsViewName: "timeseries",
MeasureNames: []string{"max_clicks"},
TimeEnd: parseTimeToProtoTimeStamps(t, "2018-01-03T00:00:00Z"),
TimeGranularity: runtimev1.TimeGrain_TIME_GRAIN_DAY,
})

require.NoError(t, err)
results := response.Data
require.Equal(t, 0, len(results))

response, err = server.MetricsViewTimeSeries(testCtx(), &runtimev1.MetricsViewTimeSeriesRequest{
InstanceId: instanceID,
MetricsViewName: "timeseries",
MeasureNames: []string{"max_clicks"},
TimeStart: parseTimeToProtoTimeStamps(t, "2022-01-01T00:00:00Z"),
TimeGranularity: runtimev1.TimeGrain_TIME_GRAIN_DAY,
})

require.NoError(t, err)
results = response.Data
require.Equal(t, 0, len(results))
}

func TestServer_Timeseries_1day_Count(t *testing.T) {
t.Parallel()
server, instanceID := getMetricsTestServer(t, "timeseries")
Expand Down

0 comments on commit 87e67ae

Please sign in to comment.