Skip to content

Commit 3f5d769

Browse files
authored
metrics: expose --fn aggregation on service metrics series (#176)
1 parent 951856e commit 3f5d769

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

internal/tiger/api/types.go

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/tiger/cmd/service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,6 +1822,7 @@ func buildServiceMetricsSeriesCmd() *cobra.Command {
18221822
var role string
18231823
var filters []string
18241824
var bucketSeconds int
1825+
var fn string
18251826
var output string
18261827

18271828
cmd := &cobra.Command{
@@ -1890,6 +1891,10 @@ Examples:
18901891
bs := bucketSeconds
18911892
body.BucketSeconds = &bs
18921893
}
1894+
if fn != "" {
1895+
f := api.MetricsSeriesRequestFn(strings.ToUpper(fn))
1896+
body.Fn = &f
1897+
}
18931898
if len(labelFilters) > 0 {
18941899
body.Filters = &labelFilters
18951900
}
@@ -1920,6 +1925,7 @@ Examples:
19201925
cmd.Flags().StringVar(&role, "role", "", "Filter to a specific instance role (PRIMARY or REPLICA)")
19211926
cmd.Flags().StringSliceVar(&filters, "filter", nil, "Arbitrary label filter as name=value (repeatable)")
19221927
cmd.Flags().IntVar(&bucketSeconds, "bucket-seconds", 0, "Aggregation bucket size in seconds (optional; server auto-selects based on the time window when omitted, minimum 60s)")
1928+
cmd.Flags().StringVar(&fn, "fn", "", "Aggregation function applied per bucket. One of: RATE, INCREASE, SUM, AVG, MIN, MAX, COUNT, P50, P90, P99, LAST. Rejected on the timescale_cloud_* resource/qps/connections/jobs metrics; omit to let the server pick the default")
19231929
cmd.Flags().VarP((*outputFlag)(&output), "output", "o", "Output format (json, yaml, table)")
19241930

19251931
cmd.MarkFlagRequired("metric")

internal/tiger/mcp/service_tools.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ type ServiceMetricsSeriesInput struct {
455455
Role string `json:"role,omitempty"`
456456
Filters []MetricLabelFilterInput `json:"filters,omitempty"`
457457
BucketSeconds int `json:"bucket_seconds,omitempty"`
458+
Fn string `json:"fn,omitempty"`
458459
}
459460

460461
func (ServiceMetricsSeriesInput) Schema() *jsonschema.Schema {
@@ -484,6 +485,10 @@ func (ServiceMetricsSeriesInput) Schema() *jsonschema.Schema {
484485
schema.Properties["bucket_seconds"].Minimum = util.Ptr(60.0)
485486
schema.Properties["bucket_seconds"].Examples = []any{60, 300, 3600}
486487

488+
schema.Properties["fn"].Description = "Aggregation function applied per bucket. Not accepted on these metrics (returns INVALID_REQUEST): timescale_cloud_system_cpu_total_millicores, timescale_cloud_system_cpu_usage_millicores, timescale_cloud_system_disk_io_read_bytes, timescale_cloud_system_disk_io_read_ops, timescale_cloud_system_disk_io_total_bytes, timescale_cloud_system_disk_io_total_ops, timescale_cloud_system_disk_io_write_bytes, timescale_cloud_system_disk_io_write_ops, timescale_cloud_system_disk_usage_bytes, timescale_cloud_system_memory_total_bytes, timescale_cloud_system_memory_usage_bytes, timescale_cloud_database_qps, timescale_cloud_database_num_connections, timescale_cloud_database_job_duration_usecs, timescale_cloud_database_job_success. When omitted, the server picks a sensible default for the metric (typically LAST)."
489+
schema.Properties["fn"].Enum = []any{"RATE", "INCREASE", "SUM", "AVG", "MIN", "MAX", "COUNT", "P50", "P90", "P99", "LAST"}
490+
schema.Properties["fn"].Examples = []any{"RATE"}
491+
487492
return schema
488493
}
489494

@@ -1420,6 +1425,10 @@ func (s *Server) handleServiceMetricsSeries(ctx context.Context, req *mcp.CallTo
14201425
bs := input.BucketSeconds
14211426
body.BucketSeconds = &bs
14221427
}
1428+
if input.Fn != "" {
1429+
fn := api.MetricsSeriesRequestFn(strings.ToUpper(input.Fn))
1430+
body.Fn = &fn
1431+
}
14231432
if len(filters) > 0 {
14241433
body.Filters = &filters
14251434
}

openapi.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,42 @@ components:
15551555
Must be coarse enough for the window's tier; requests that ask
15561556
for a finer bucket than the tier can produce are rejected.
15571557
example: 3600
1558+
fn:
1559+
type: string
1560+
enum:
1561+
- RATE
1562+
- INCREASE
1563+
- SUM
1564+
- AVG
1565+
- MIN
1566+
- MAX
1567+
- COUNT
1568+
- P50
1569+
- P90
1570+
- P99
1571+
- LAST
1572+
description: |
1573+
Aggregation function applied per bucket. Optional: when omitted,
1574+
the server picks the default for the metric (currently `LAST`).
1575+
1576+
Not accepted on the following metrics — requests are rejected
1577+
with `INVALID_REQUEST`:
1578+
- `timescale_cloud_system_cpu_total_millicores`
1579+
- `timescale_cloud_system_cpu_usage_millicores`
1580+
- `timescale_cloud_system_disk_io_read_bytes`
1581+
- `timescale_cloud_system_disk_io_read_ops`
1582+
- `timescale_cloud_system_disk_io_total_bytes`
1583+
- `timescale_cloud_system_disk_io_total_ops`
1584+
- `timescale_cloud_system_disk_io_write_bytes`
1585+
- `timescale_cloud_system_disk_io_write_ops`
1586+
- `timescale_cloud_system_disk_usage_bytes`
1587+
- `timescale_cloud_system_memory_total_bytes`
1588+
- `timescale_cloud_system_memory_usage_bytes`
1589+
- `timescale_cloud_database_qps`
1590+
- `timescale_cloud_database_num_connections`
1591+
- `timescale_cloud_database_job_duration_usecs`
1592+
- `timescale_cloud_database_job_success`
1593+
example: "RATE"
15581594
filters:
15591595
type: array
15601596
description: |

0 commit comments

Comments
 (0)