MCPcopy Create free account
hub / github.com/rilldata/rill / newBuiltinMetricsSQL

Function newBuiltinMetricsSQL

runtime/resolvers/builtin_metrics_sql.go:48–73  ·  view source on GitHub ↗

newBuiltinMetricsSQL is the resolver for the built-in /metrics-sql API. It executes a metrics SQL query provided dynamically through the args. It errors if the user identified by the attributes is not an admin.

(ctx context.Context, opts *runtime.ResolverOptions)

Source from the content-addressed store, hash-verified

46// It executes a metrics SQL query provided dynamically through the args.
47// It errors if the user identified by the attributes is not an admin.
48func newBuiltinMetricsSQL(ctx context.Context, opts *runtime.ResolverOptions) (runtime.Resolver, error) {
49 // Only admins can run arbitrary SQL queries.
50 if !opts.Claims.SkipChecks && !opts.Claims.Admin() {
51 return nil, errors.New("must be an admin to run arbitrary SQL queries")
52 }
53
54 // Decode the args
55 args := &builtinMetricsSQLArgs{}
56 if err := mapstructure.Decode(opts.Args, args); err != nil {
57 return nil, err
58 }
59
60 // Rewrite to the metrics SQL resolver
61 return newMetricsSQL(ctx, &runtime.ResolverOptions{
62 Runtime: opts.Runtime,
63 InstanceID: opts.InstanceID,
64 Properties: map[string]any{
65 "sql": args.SQL,
66 },
67 Args: map[string]any{
68 "priority": args.Priority,
69 },
70 Claims: opts.Claims,
71 ForExport: opts.ForExport,
72 })
73}

Callers

nothing calls this directly

Calls 3

newMetricsSQLFunction · 0.85
AdminMethod · 0.45
DecodeMethod · 0.45

Tested by

no test coverage detected