Files
zeekay c3dc2f1ecf Read the event plane, not what it replaced
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.
2026-09-08 23:07:06 -07:00

104 lines
3.7 KiB
Go

package app
import (
"encoding/json"
"strings"
"github.com/hanzoai/o11y/pkg/querier"
v3 "github.com/hanzoai/o11y/pkg/query-service/model/v3"
)
// TODO(srikanthccv): Move to the querier layer
type QueryInfoResult struct {
Version string `json:"version"`
LogsUsed bool `json:"logs_used,omitempty"`
MetricsUsed bool `json:"metrics_used,omitempty"`
TracesUsed bool `json:"traces_used,omitempty"`
FilterApplied bool `json:"filter_applied,omitempty"`
GroupByApplied bool `json:"group_by_applied,omitempty"`
AggregateOperator v3.AggregateOperator `json:"aggregate_operator,omitempty"`
AggregateAttributeKey string `json:"aggregate_attribute_key,omitempty"`
QueryType v3.QueryType `json:"query_type,omitempty"`
PanelType v3.PanelType `json:"panel_type,omitempty"`
NumberOfQueries int `json:"number_of_queries,omitempty"`
}
func NewQueryInfoResult(postData *v3.QueryRangeParamsV3, version string) QueryInfoResult {
queryInfoResult := QueryInfoResult{
Version: version,
}
if postData == nil {
return queryInfoResult
}
if postData.CompositeQuery == nil {
return queryInfoResult
}
queryInfoResult.PanelType = postData.CompositeQuery.PanelType
queryInfoResult.QueryType = postData.CompositeQuery.QueryType
if postData.CompositeQuery.QueryType == v3.QueryTypeBuilder {
queryInfoResult.NumberOfQueries = len(postData.CompositeQuery.BuilderQueries)
for _, query := range postData.CompositeQuery.BuilderQueries {
if query.DataSource == v3.DataSourceLogs {
queryInfoResult.LogsUsed = true
} else if query.DataSource == v3.DataSourceMetrics {
queryInfoResult.MetricsUsed = true
} else if query.DataSource == v3.DataSourceTraces {
queryInfoResult.TracesUsed = true
}
if query.Filters != nil && len(query.Filters.Items) > 0 {
queryInfoResult.FilterApplied = true
}
if query.GroupBy != nil && len(query.GroupBy) > 0 {
queryInfoResult.GroupByApplied = true
}
queryInfoResult.AggregateOperator = query.AggregateOperator
if len(query.AggregateAttribute.Key) > 0 && !strings.Contains(query.AggregateAttribute.Key, "o11y_") {
queryInfoResult.AggregateAttributeKey = query.AggregateAttribute.Key
}
}
} else if postData.CompositeQuery.QueryType == v3.QueryTypePromQL {
for _, query := range postData.CompositeQuery.PromQueries {
if !strings.Contains(query.Query, "o11y_") && len(query.Query) > 0 {
queryInfoResult.MetricsUsed = true
}
}
} else if postData.CompositeQuery.QueryType == v3.QueryTypeDatastoreSQL {
// This block asked which DATABASE the SQL named — o11y_metrics,
// o11y_logs, o11y_traces. HIP-0132 unified all three into `event`, so
// all three tests went permanently false and raw-SQL queries were
// recorded as touching no signal at all. querier.SignalsInSQL is the one
// answer to that question; there is no second copy of it here.
for _, query := range postData.CompositeQuery.DatastoreQueries {
if len(query.Query) == 0 {
continue
}
m, l, t := querier.SignalsInSQL(query.Query)
queryInfoResult.MetricsUsed = queryInfoResult.MetricsUsed || m
queryInfoResult.LogsUsed = queryInfoResult.LogsUsed || l
queryInfoResult.TracesUsed = queryInfoResult.TracesUsed || t
}
}
return queryInfoResult
}
func (queryInfoResult QueryInfoResult) ToMap() map[string]interface{} {
marshalled, err := json.Marshal(queryInfoResult)
if err != nil {
return nil
}
var result map[string]interface{}
err = json.Unmarshal(marshalled, &result)
if err != nil {
return nil
}
return result
}