mirror of
https://github.com/hanzoai/o11y.git
synced 2026-10-15 12:58:33 +00:00
HIP-0132 unified o11y_logs, o11y_traces and o11y_metrics into one `event`
database and dropped them. The commit that restored the reads repointed
three files and said so; it was thirty. The rest went on naming databases
that no longer exist, so trace funnels, the Kafka and queue panels, the
v3/v4 logs and traces builders and the PromQL adapter each answered
Code: 81 UNKNOWN_DATABASE, and the golden tests agreed with them because
they pinned the same dead SQL.
pkg/telemetryplane is the one address for the name, imports nothing, and
is reachable from every depth that needs it. Its test walks the tree and
fails the build on a literal that names a dropped database, tests
included — a golden encoding broken SQL is a second vote for the bug, not
coverage.
Two service views turned a failed read into an offer to instrument an
already-instrumented application. A failure now shows the failure, and
onboarding is offered on a successful empty read.
Cherry-picked from salvage/blue-wt-o11y-readers 83ecbec03c.
211 lines
6.1 KiB
Go
211 lines
6.1 KiB
Go
package datastore
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestTransform(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
name string
|
|
sql string
|
|
variables []VariableValue
|
|
expected string
|
|
}{
|
|
{
|
|
name: "Example 1: Only service_name is __all__",
|
|
sql: `SELECT trace_id, name, kind, status
|
|
FROM event.span
|
|
WHERE service_name = $service_name
|
|
AND operation_name IN ($operation_names)
|
|
AND duration >= $min_duration
|
|
AND attributes['http.method'] = $http_method
|
|
AND op IN (SELECT op FROM event.operation WHERE service_name = $service_name AND kind = 'server')
|
|
AND timestamp BETWEEN $start_time AND $end_time`,
|
|
|
|
// Define our variables and their values/metadata
|
|
variables: []VariableValue{
|
|
{
|
|
Name: "service_name",
|
|
Values: []string{"__all__"}, // User selected "__all__"
|
|
IsSelectAll: true,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "operation_names",
|
|
Values: []string{"op1", "op2", "op3"},
|
|
IsSelectAll: false, // User selected specific values
|
|
FieldType: "array",
|
|
},
|
|
{
|
|
Name: "min_duration",
|
|
Values: []string{"100"},
|
|
IsSelectAll: false,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "http_method",
|
|
Values: []string{"GET", "POST"},
|
|
IsSelectAll: false,
|
|
FieldType: "map", // This is a map lookup
|
|
},
|
|
{
|
|
Name: "start_time",
|
|
Values: []string{"2023-01-01 00:00:00"},
|
|
IsSelectAll: false,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "end_time",
|
|
Values: []string{"2023-01-02 00:00:00"},
|
|
IsSelectAll: false,
|
|
FieldType: "scalar",
|
|
},
|
|
},
|
|
expected: `SELECT trace_id, name, kind, status FROM event.span WHERE operation_name IN ($operation_names) AND duration >= $min_duration AND attributes['http.method'] = $http_method AND op IN (SELECT op FROM event.operation WHERE kind = 'server') AND timestamp BETWEEN $start_time AND $end_time;`,
|
|
},
|
|
{
|
|
name: "Example 2: Multiple __all__ selections and map lookups",
|
|
sql: `SELECT trace_id, name, kind, status
|
|
FROM event.span
|
|
WHERE service_name = $service_name
|
|
AND operation_name IN ($operation_names)
|
|
AND duration >= $min_duration
|
|
AND attributes['http.method'] = $http_method
|
|
AND op IN (SELECT op FROM event.operation WHERE service_name = $service_name AND kind = 'server')
|
|
AND timestamp BETWEEN $start_time AND $end_time`,
|
|
|
|
variables: []VariableValue{
|
|
{
|
|
Name: "service_name",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "operation_names",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "array",
|
|
},
|
|
{
|
|
Name: "min_duration",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "http_method",
|
|
Values: []string{"GET", "POST"},
|
|
IsSelectAll: false,
|
|
FieldType: "map",
|
|
},
|
|
{
|
|
Name: "start_time",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "end_time",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "scalar",
|
|
},
|
|
},
|
|
expected: `SELECT trace_id, name, kind, status FROM event.span WHERE attributes['http.method'] = $http_method AND op IN (SELECT op FROM event.operation WHERE kind = 'server') AND timestamp BETWEEN $start_time AND $end_time;`,
|
|
},
|
|
{
|
|
name: "Example 3: Multiple __all__ selections and map lookups",
|
|
sql: `SELECT trace_id, name, kind, status
|
|
FROM event.span
|
|
WHERE service_name = $service_name
|
|
AND operation_name IN ($operation_names)
|
|
AND duration >= $min_duration
|
|
AND attributes['http.method'] = $http_method
|
|
AND op IN (SELECT op FROM event.operation WHERE service_name = $service_name AND kind = 'server')
|
|
AND timestamp BETWEEN $start_time AND $end_time`,
|
|
|
|
variables: []VariableValue{
|
|
{
|
|
Name: "service_name",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "operation_names",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "array",
|
|
},
|
|
{
|
|
Name: "min_duration",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "http_method",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "map",
|
|
},
|
|
},
|
|
expected: `SELECT trace_id, name, kind, status FROM event.span WHERE op IN (SELECT op FROM event.operation WHERE kind = 'server') AND timestamp BETWEEN $start_time AND $end_time;`,
|
|
},
|
|
{
|
|
name: "Example 3: Multiple __all__ selections and map lookups",
|
|
sql: `SELECT trace_id, name, kind, status
|
|
FROM event.span
|
|
WHERE service_name = {{service_name}}
|
|
AND operation_name IN {{.operation_names}}
|
|
AND duration >= {{min_duration}}
|
|
AND attributes['http.method'] = $http_method
|
|
AND op IN (SELECT op FROM event.operation WHERE service_name = {{service_name}} AND kind = 'server')`,
|
|
|
|
variables: []VariableValue{
|
|
{
|
|
Name: "service_name",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "operation_names",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "array",
|
|
},
|
|
{
|
|
Name: "min_duration",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "scalar",
|
|
},
|
|
{
|
|
Name: "http_method",
|
|
Values: []string{"__all__"},
|
|
IsSelectAll: true,
|
|
FieldType: "map",
|
|
},
|
|
},
|
|
expected: `SELECT trace_id, name, kind, status FROM event.span WHERE op IN (SELECT op FROM event.operation WHERE kind = 'server');`,
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
transformer := NewQueryTransformer(testCase.sql, testCase.variables)
|
|
modifiedQuery, err := transformer.Transform()
|
|
if err != nil {
|
|
t.Fatalf("Error transforming query: %v", err)
|
|
}
|
|
|
|
if modifiedQuery != testCase.expected {
|
|
t.Errorf("Expected transformed query to be:\n%s\nBut got:\n%s", testCase.expected, modifiedQuery)
|
|
}
|
|
})
|
|
}
|
|
}
|