Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions internal/commands/admin/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ Each row carries an MQE-ready entity to paste into a follow-up "swctl metrics ex

Examples:
1. Entities reporting service_cpm in the last 30 minutes:
$ swctl admin inspect entities --metric service_cpm`,
$ swctl admin inspect entities --metric service_cpm

2. Inspect a metric persisted by ANOTHER OAP (not defined on this OAP) — supply its value
column + type so the OAP resolves it from storage without its local registry:
$ swctl admin inspect entities --metric meter_foo --value-column value --value-type LONG`,
Flags: flags.Flags(
flags.DurationFlags,
[]cli.Flag{
Expand All @@ -105,6 +109,14 @@ $ swctl admin inspect entities --metric service_cpm`,
Name: "limit",
Usage: fmt.Sprintf("max rows scanned at the storage layer (1-%d, server default 300)", inspect.MaxLimit),
},
&cli.StringFlag{
Name: "value-column",
Usage: "the metric's value `column` (e.g. value, value_, double_value); REQUIRED when the metric is not defined on the target OAP",
},
&cli.StringFlag{
Name: "value-type",
Usage: "value data `type` (LONG / INT / DOUBLE / LABELED); REQUIRED when the metric is not defined on the target OAP",
},
},
),
Before: interceptor.BeforeChain(
Expand All @@ -117,12 +129,14 @@ $ swctl admin inspect entities --metric service_cpm`,
}
step := ctx.Generic("step").(*model.StepEnumValue).Selected

entities, err := inspect.ListEntities(ctx.Context, inspect.EntitiesOptions{
Metric: ctx.String("metric"),
Start: ctx.String("start"),
End: ctx.String("end"),
Step: string(step),
Limit: limit,
entities, err := inspect.ListEntities(ctx.Context, &inspect.EntitiesOptions{
Metric: ctx.String("metric"),
Start: ctx.String("start"),
End: ctx.String("end"),
Step: string(step),
Limit: limit,
ValueColumn: ctx.String("value-column"),
ValueType: ctx.String("value-type"),
})
if err != nil {
return preflight.Explain(ctx.Context, err, preflight.ModuleInspect, "SW_INSPECT")
Expand Down
13 changes: 12 additions & 1 deletion pkg/admin/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ type EntitiesOptions struct {
End string
Step string
Limit int
// ValueColumn / ValueType are required only when the metric is NOT defined on the target OAP
// (a metric persisted by another OAP). When set, the OAP resolves the metric from storage
// using this caller-supplied metadata instead of its local registry.
ValueColumn string
ValueType string
}

// ListMetrics lists the registered metric catalog (GET /inspect/metrics).
Expand All @@ -107,7 +112,7 @@ func ListMetrics(ctx context.Context, opts MetricsOptions) (*Metrics, error) {

// ListEntities enumerates the entities holding values for a metric over a time range
// (GET /inspect/entities). Only REGULAR_VALUE / LABELED_VALUE metrics are accepted.
func ListEntities(ctx context.Context, opts EntitiesOptions) (*Entities, error) {
func ListEntities(ctx context.Context, opts *EntitiesOptions) (*Entities, error) {
query := url.Values{}
query.Set("metric", opts.Metric)
query.Set("start", opts.Start)
Expand All @@ -116,6 +121,12 @@ func ListEntities(ctx context.Context, opts EntitiesOptions) (*Entities, error)
if opts.Limit > 0 {
query.Set("limit", strconv.Itoa(opts.Limit))
}
if opts.ValueColumn != "" {
query.Set("valueColumn", opts.ValueColumn)
}
if opts.ValueType != "" {
query.Set("valueType", opts.ValueType)
}

var out Entities
err := client.GetJSON(ctx, "/inspect/entities", query, &out)
Expand Down
Loading