From 9a52bcd373e856625edbb03662fe0eb4a6511064 Mon Sep 17 00:00:00 2001 From: Yury Frolov Date: Fri, 13 Sep 2024 10:01:47 +0500 Subject: [PATCH 1/2] Change output type of 'SHOW time_quantiles' to float8 --- pkg/clientinteractor/interactor.go | 26 ++++++++++++++++--- test/regress/conf/router.yaml | 2 +- .../console/expected/show_time_quantiles.out | 8 +++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/pkg/clientinteractor/interactor.go b/pkg/clientinteractor/interactor.go index 3a3eb4c67..abfb268b0 100644 --- a/pkg/clientinteractor/interactor.go +++ b/pkg/clientinteractor/interactor.go @@ -82,6 +82,9 @@ func (pi *PSQLInteractor) CompleteMsg(rowCnt int) error { // TEXTOID https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat#L81 const TEXTOID = 25 +// DOUBLEOID https://github.com/postgres/postgres/blob/master/src/include/catalog/pg_type.dat#L223 +const DOUBLEOID = 701 + // TODO : unit tests // TextOidFD generates a pgproto3.FieldDescription object with the provided statement text. @@ -103,6 +106,18 @@ func TextOidFD(stmt string) pgproto3.FieldDescription { } } +func FloatOidFD(stmt string) pgproto3.FieldDescription { + return pgproto3.FieldDescription{ + Name: []byte(stmt), + TableOID: 0, + TableAttributeNumber: 0, + DataTypeOID: DOUBLEOID, + DataTypeSize: 8, + TypeModifier: -1, + Format: 0, + } +} + // TODO : unit tests // WriteHeader sends the row description message with the specified field descriptions. @@ -251,17 +266,20 @@ func (pi *PSQLInteractor) Version(_ context.Context) error { // // TODO: unit tests func (pi *PSQLInteractor) Quantiles(_ context.Context) error { - if err := pi.WriteHeader("quantile_type", "value"); err != nil { - spqrlog.Zero.Error().Err(err).Msg("") + if err := pi.cl.Send(&pgproto3.RowDescription{ + Fields: []pgproto3.FieldDescription{TextOidFD("quantile_type"), FloatOidFD("time, ms")}, + }); err != nil { + spqrlog.Zero.Error().Err(err).Msg("Could not write header for time quantiles") return err } quantiles := statistics.GetQuantiles() + spqrlog.Zero.Debug().Str("quantiles", fmt.Sprintf("%#v", quantiles)).Msg("Got quantiles") for _, q := range *quantiles { - if err := pi.WriteDataRow(fmt.Sprintf("router_time_%.2f", q), fmt.Sprintf("%.2fms", statistics.GetTotalTimeQuantile(statistics.Router, q))); err != nil { + if err := pi.WriteDataRow(fmt.Sprintf("router_time_%.2f", q), fmt.Sprintf("%.2f", statistics.GetTotalTimeQuantile(statistics.Router, q))); err != nil { return err } - if err := pi.WriteDataRow(fmt.Sprintf("shard_time_%.2f", q), fmt.Sprintf("%.2fms", statistics.GetTotalTimeQuantile(statistics.Shard, q))); err != nil { + if err := pi.WriteDataRow(fmt.Sprintf("shard_time_%.2f", q), fmt.Sprintf("%.2f", statistics.GetTotalTimeQuantile(statistics.Shard, q))); err != nil { return err } } diff --git a/test/regress/conf/router.yaml b/test/regress/conf/router.yaml index 1e961767e..98ce40a57 100644 --- a/test/regress/conf/router.yaml +++ b/test/regress/conf/router.yaml @@ -3,7 +3,7 @@ router_port: '6432' admin_console_port: '7432' grpc_api_port: '7000' router_mode: PROXY -log_level: fatal +log_level: debug time_quantiles: - 0.75 world_shard_fallback: true diff --git a/test/regress/tests/console/expected/show_time_quantiles.out b/test/regress/tests/console/expected/show_time_quantiles.out index 641bf56f5..3c5eef59c 100644 --- a/test/regress/tests/console/expected/show_time_quantiles.out +++ b/test/regress/tests/console/expected/show_time_quantiles.out @@ -6,9 +6,9 @@ https://github.com/pg-sharding/spqr/tree/master/docs SHOW time_quantiles - quantile_type | value -------------------+-------- - router_time_0.75 | 0.00ms - shard_time_0.75 | 0.00ms + quantile_type | time, ms +------------------+---------- + router_time_0.75 | 0.00 + shard_time_0.75 | 0.00 (2 rows) From a12a1626cc907ee339191b04a0d96fcb5fb6d4c4 Mon Sep 17 00:00:00 2001 From: Yury Frolov Date: Mon, 16 Sep 2024 15:15:15 +0500 Subject: [PATCH 2/2] Remove debug output --- test/regress/conf/router.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/regress/conf/router.yaml b/test/regress/conf/router.yaml index 98ce40a57..1e961767e 100644 --- a/test/regress/conf/router.yaml +++ b/test/regress/conf/router.yaml @@ -3,7 +3,7 @@ router_port: '6432' admin_console_port: '7432' grpc_api_port: '7000' router_mode: PROXY -log_level: debug +log_level: fatal time_quantiles: - 0.75 world_shard_fallback: true