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

Function TestMetricsView

runtime/controller_test.go:821–1017  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

819}
820
821func TestMetricsView(t *testing.T) {
822 // Create source and model
823 rt, id := testruntime.NewInstance(t)
824 testruntime.PutFiles(t, rt, id, map[string]string{
825 "/data/foo.csv": `a,b,c,d,e
8261,2,3,4,5
8271,2,3,4,5
8281,2,3,4,5
829`,
830 "/sources/foo.yaml": `
831connector: local_file
832path: data/foo.csv
833`,
834 "/models/bar.sql": `SELECT * FROM foo`,
835 "/metrics/dash.yaml": `
836version: 1
837type: metrics_view
838display_name: Dash
839model: bar
840dimensions:
841- column: b
842- column: c
843measures:
844- expression: count(*)
845- expression: avg(a)
846`,
847 })
848
849 _, metricsRes := newMetricsView("dash", "bar", "", []any{"count(*)", runtimev1.Type_CODE_INT64, "avg(a)", runtimev1.Type_CODE_FLOAT64}, []any{"b", runtimev1.Type_CODE_INT64, "c", runtimev1.Type_CODE_INT64})
850 testruntime.ReconcileParserAndWait(t, rt, id)
851 testruntime.RequireReconcileState(t, rt, id, 4, 0, 0)
852 testruntime.RequireResource(t, rt, id, metricsRes)
853
854 // ignore invalid measure and dimension
855 testruntime.PutFiles(t, rt, id, map[string]string{
856 "/metrics/dash.yaml": `
857version: 1
858type: metrics_view
859display_name: Dash
860model: bar
861dimensions:
862- column: b
863- column: f
864 ignore: true
865measures:
866- expression: count(*)
867- expression: avg(g)
868 ignore: true
869`,
870 })
871 _, metricsRes = newMetricsView("dash", "bar", "", []any{"count(*)", runtimev1.Type_CODE_INT64}, []any{"b", runtimev1.Type_CODE_INT64})
872 testruntime.ReconcileParserAndWait(t, rt, id)
873 testruntime.RequireReconcileState(t, rt, id, 4, 0, 0)
874 testruntime.RequireResource(t, rt, id, metricsRes)
875
876 // no measure, invalid dashboard
877 testruntime.PutFiles(t, rt, id, map[string]string{
878 "/metrics/dash.yaml": `

Callers

nothing calls this directly

Calls 9

NewInstanceFunction · 0.92
PutFilesFunction · 0.92
ReconcileParserAndWaitFunction · 0.92
RequireReconcileStateFunction · 0.92
RequireResourceFunction · 0.92
RequireParseErrorsFunction · 0.92
GetResourceFunction · 0.92
newMetricsViewFunction · 0.70
GetMetricsViewMethod · 0.45

Tested by

no test coverage detected