Skip to content

Commit

Permalink
feat: add search span scope in the list view tab to add the scope at …
Browse files Browse the repository at this point in the history
…per query level
  • Loading branch information
eKuG committed Jan 13, 2025
1 parent d5b847c commit 0346e52
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/query-service/app/traces/v4/query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,18 @@ func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, panelType v3.
if len(mq.SelectColumns) == 0 {
return "", fmt.Errorf("select columns cannot be empty for panelType %s", panelType)
}
// add it to the select labels
selectLabels = getSelectLabels(mq.SelectColumns)
queryNoOpTmpl := fmt.Sprintf("SELECT timestamp as timestamp_datetime, spanID, traceID,%s ", selectLabels) + "from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_SPAN_INDEX_V3 + " where %s %s" + "%s"
query = fmt.Sprintf(queryNoOpTmpl, timeFilter, filterSubQuery, orderBy)
if mq.SpanSearchScope == v3.SpanSearchScopeAll || mq.SpanSearchScope == "" {
// add it to the select labels
queryNoOpTmpl := fmt.Sprintf("SELECT timestamp as timestamp_datetime, spanID, traceID,%s ", selectLabels) + "from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_SPAN_INDEX_V3 + " where %s %s" + "%s"
query = fmt.Sprintf(queryNoOpTmpl, timeFilter, filterSubQuery, orderBy)
} else if mq.SpanSearchScope == v3.SpanSearchScopeEntryPoint {
queryNoOpTmpl := fmt.Sprintf("SELECT timestamp as timestamp_datetime, span_id, trace_id,%s ", selectLabels) + "from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_SPAN_INDEX_V3 + " where ((name, `resource_string_service$$name`) IN ( SELECT DISTINCT name, serviceName from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_TOP_LEVEL_OPERATIONS_TABLENAME + " )) and %s %s" + "%s"
query = fmt.Sprintf(queryNoOpTmpl, timeFilter, filterSubQuery, orderBy)
} else if mq.SpanSearchScope == v3.SpanSearchScopeRoot {
queryNoOpTmpl := fmt.Sprintf("SELECT timestamp as timestamp_datetime, spanID, traceID,%s ", selectLabels) + "from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_SPAN_INDEX_V3 + " where parent_span_id = '' AND %s %s" + "%s"
query = fmt.Sprintf(queryNoOpTmpl, timeFilter, filterSubQuery, orderBy)
}
} else {
return "", fmt.Errorf("unsupported aggregate operator %s for panelType %s", mq.AggregateOperator, panelType)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/query-service/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ const (
SIGNOZ_TIMESERIES_v4_1DAY_LOCAL_TABLENAME = "time_series_v4_1day"
SIGNOZ_TIMESERIES_v4_1WEEK_LOCAL_TABLENAME = "time_series_v4_1week"
SIGNOZ_TIMESERIES_v4_1DAY_TABLENAME = "distributed_time_series_v4_1day"
SIGNOZ_TOP_LEVEL_OPERATIONS_TABLENAME = "distributed_top_level_operations"
)

var TimeoutExcludedRoutes = map[string]bool{
Expand Down
21 changes: 21 additions & 0 deletions pkg/query-service/model/v3/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ func (d DataSource) Validate() error {
}
}

type SpanSearchScope string

const (
SpanSearchScopeAll SpanSearchScope = "all_spans"
SpanSearchScopeEntryPoint SpanSearchScope = "entry_point_spans"
SpanSearchScopeRoot SpanSearchScope = "root_spans"
)

func (s SpanSearchScope) validateSpanScope() error {
if s == "" {
return nil
}
switch s {
case SpanSearchScopeAll, SpanSearchScopeEntryPoint, SpanSearchScopeRoot:
return nil
default:
return fmt.Errorf("invalid span search scope: %s", s)
}
}

type AggregateOperator string

const (
Expand Down Expand Up @@ -786,6 +806,7 @@ func (m *MetricValueFilter) Clone() *MetricValueFilter {
type BuilderQuery struct {
QueryName string `json:"queryName"`
StepInterval int64 `json:"stepInterval"`
SpanSearchScope SpanSearchScope `json:"spanSearchScope,omitempty"`
DataSource DataSource `json:"dataSource"`
AggregateOperator AggregateOperator `json:"aggregateOperator"`
AggregateAttribute AttributeKey `json:"aggregateAttribute,omitempty"`
Expand Down

0 comments on commit 0346e52

Please sign in to comment.