From 3bf2a5c3577166d341f07c2fe128147a48dd416f Mon Sep 17 00:00:00 2001 From: Artem Poltorzhitskiy Date: Tue, 16 Jul 2024 01:30:28 +0200 Subject: [PATCH] Feature: add hour timeframe to cumulative series (#251) --- cmd/api/docs/swagger.json | 1 + cmd/api/handler/stats.go | 4 ++-- cmd/api/handler/stats_test.go | 1 + internal/storage/postgres/stats.go | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/api/docs/swagger.json b/cmd/api/docs/swagger.json index f2ab67cf..54bb1467 100644 --- a/cmd/api/docs/swagger.json +++ b/cmd/api/docs/swagger.json @@ -3522,6 +3522,7 @@ "parameters": [ { "enum": [ + "hour", "day", "week", "month", diff --git a/cmd/api/handler/stats.go b/cmd/api/handler/stats.go index af05e10d..cba15033 100644 --- a/cmd/api/handler/stats.go +++ b/cmd/api/handler/stats.go @@ -225,7 +225,7 @@ func (sh StatsHandler) Series(c echo.Context) error { } type seriesCumulativeRequest struct { - Timeframe string `example:"day" param:"timeframe" swaggertype:"string" validate:"required,oneof=day week month year"` + Timeframe string `example:"day" param:"timeframe" swaggertype:"string" validate:"required,oneof=hour day week month year"` SeriesName string `example:"tps" param:"name" swaggertype:"string" validate:"required,oneof=blobs_size blobs_count fee tx_count gas_used gas_limit bytes_in_block supply_change"` From int64 `example:"1692892095" query:"from" swaggertype:"integer" validate:"omitempty,min=1"` To int64 `example:"1692892095" query:"to" swaggertype:"integer" validate:"omitempty,min=1"` @@ -237,7 +237,7 @@ type seriesCumulativeRequest struct { // @Description Get cumulative histogram with precomputed stats by series name and timeframe // @Tags stats // @ID stats-series-cumulative -// @Param timeframe path string true "Timeframe" Enums(day, week, month, year) +// @Param timeframe path string true "Timeframe" Enums(hour, day, week, month, year) // @Param name path string true "Series name" Enums(blobs_size, blobs_count, fee, tx_count, gas_used, gas_limit, bytes_in_block, supply_change) // @Param from query integer false "Time from in unix timestamp" mininum(1) // @Param to query integer false "Time to in unix timestamp" mininum(1) diff --git a/cmd/api/handler/stats_test.go b/cmd/api/handler/stats_test.go index 2f311e24..8d70fec2 100644 --- a/cmd/api/handler/stats_test.go +++ b/cmd/api/handler/stats_test.go @@ -485,6 +485,7 @@ func (s *StatsTestSuite) TestCumulativeSeries() { } { for _, tf := range []storage.Timeframe{ + storage.TimeframeHour, storage.TimeframeDay, storage.TimeframeWeek, storage.TimeframeMonth, diff --git a/internal/storage/postgres/stats.go b/internal/storage/postgres/stats.go index 70964ebf..eb1bd901 100644 --- a/internal/storage/postgres/stats.go +++ b/internal/storage/postgres/stats.go @@ -239,6 +239,8 @@ func (s Stats) NamespaceSeries(ctx context.Context, timeframe storage.Timeframe, func (s Stats) CumulativeSeries(ctx context.Context, timeframe storage.Timeframe, name string, req storage.SeriesRequest) (response []storage.SeriesItem, err error) { query := s.db.DB().NewSelect() switch timeframe { + case storage.TimeframeHour: + query.Table(storage.ViewBlockStatsByHour) case storage.TimeframeDay: query.Table(storage.ViewBlockStatsByDay) case storage.TimeframeWeek: