Skip to content

Commit

Permalink
refactor(query): move window size setter to connector (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike authored Apr 16, 2024
1 parent 59f1d0a commit 5e343f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 0 additions & 12 deletions internal/server/router/meter_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,6 @@ func (a *Router) QueryMeterWithMeter(ctx context.Context, w http.ResponseWriter,
Data: data,
}

// If total data is queried for a period, replace the window start and end with the period for each row
if params.WindowSize == nil {
for i := range resp.Data {
if params.From != nil {
resp.Data[i].WindowStart = *params.From
}
if params.To != nil {
resp.Data[i].WindowEnd = *params.To
}
}
}

// Parse media type
accept := r.Header.Get("Accept")
if accept == "" {
Expand Down
14 changes: 14 additions & 0 deletions internal/streaming/clickhouse_connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,20 @@ func (c *ClickhouseConnector) QueryMeter(ctx context.Context, namespace string,
return nil, fmt.Errorf("get values: %w", err)
}

// If the total usage is queried for a single period (no window size),
// replace the window start and end with the period for each row.
// We can still have multiple rows for a single period due to group bys.
if params.WindowSize == nil {
for i := range values {
if params.From != nil {
values[i].WindowStart = *params.From
}
if params.To != nil {
values[i].WindowEnd = *params.To
}
}
}

return values, nil
}

Expand Down

0 comments on commit 5e343f1

Please sign in to comment.