From 0346e520ec9ff4b46cbb34fe4dca313b96285eb9 Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 13 Jan 2025 18:35:36 +0530 Subject: [PATCH 01/11] feat: add search span scope in the list view tab to add the scope at per query level --- .../app/traces/v4/query_builder.go | 14 ++++++++++--- pkg/query-service/constants/constants.go | 1 + pkg/query-service/model/v3/v3.go | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pkg/query-service/app/traces/v4/query_builder.go b/pkg/query-service/app/traces/v4/query_builder.go index 80d39b9016a..9b513c37cfa 100644 --- a/pkg/query-service/app/traces/v4/query_builder.go +++ b/pkg/query-service/app/traces/v4/query_builder.go @@ -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) } diff --git a/pkg/query-service/constants/constants.go b/pkg/query-service/constants/constants.go index 242b2cd4a39..13952b20595 100644 --- a/pkg/query-service/constants/constants.go +++ b/pkg/query-service/constants/constants.go @@ -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{ diff --git a/pkg/query-service/model/v3/v3.go b/pkg/query-service/model/v3/v3.go index 158718a12b4..9aa52bd9da9 100644 --- a/pkg/query-service/model/v3/v3.go +++ b/pkg/query-service/model/v3/v3.go @@ -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 ( @@ -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"` From 75b4d8915cb013b3af654192bcbcdfa09fb94a28 Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 13 Jan 2025 19:40:33 +0530 Subject: [PATCH 02/11] feat: add search span scope in the list view tab to add the scope at per query level --- .../app/traces/v4/query_builder_test.go | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pkg/query-service/app/traces/v4/query_builder_test.go b/pkg/query-service/app/traces/v4/query_builder_test.go index a9b055b67f5..e6c6ef2082b 100644 --- a/pkg/query-service/app/traces/v4/query_builder_test.go +++ b/pkg/query-service/app/traces/v4/query_builder_test.go @@ -552,6 +552,40 @@ func Test_buildTracesQuery(t *testing.T) { want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) order by timestamp ASC", }, + { + name: "test noop list view with entry_point_spans", + args: args{ + panelType: v3.PanelTypeList, + start: 1680066360726210000, + end: 1680066458000000000, + mq: &v3.BuilderQuery{ + AggregateOperator: v3.AggregateOperatorNoOp, + SpanSearchScope: v3.SpanSearchScopeEntryPoint, + Filters: &v3.FilterSet{}, + SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, + OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, + }, + }, + want: "SELECT timestamp as timestamp_datetime, span_id, trace_id, name as `name` from signoz_traces.distributed_signoz_index_v3 where ((name, `resource_string_service$$name`) IN ( SELECT DISTINCT name, serviceName from signoz_traces.distributed_top_level_operations )) and (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) order by timestamp ASC", + }, + { + name: "test noop list view with root_spans", + args: args{ + panelType: v3.PanelTypeList, + start: 1680066360726210000, + end: 1680066458000000000, + mq: &v3.BuilderQuery{ + AggregateOperator: v3.AggregateOperatorNoOp, + SpanSearchScope: v3.SpanSearchScopeRoot, + Filters: &v3.FilterSet{}, + SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, + OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, + }, + }, + want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where parent_span_id = '' AND (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) order by timestamp ASC", + }, { name: "test noop list view-without ts", args: args{ From 01294b9796c4791c90abf05828b8a168e7e8e934 Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 20 Jan 2025 15:27:53 +0530 Subject: [PATCH 03/11] feat: add search span scope in the list view tab to add the scope at per query level --- .../app/traces/v4/query_builder.go | 43 +++++++++++++------ pkg/query-service/constants/constants.go | 3 ++ pkg/query-service/model/v3/v3.go | 22 +--------- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/pkg/query-service/app/traces/v4/query_builder.go b/pkg/query-service/app/traces/v4/query_builder.go index 9b513c37cfa..36ec587fde7 100644 --- a/pkg/query-service/app/traces/v4/query_builder.go +++ b/pkg/query-service/app/traces/v4/query_builder.go @@ -94,7 +94,7 @@ func buildTracesFilterQuery(fs *v3.FilterSet) (string, error) { for _, item := range fs.Items { // skip if it's a resource attribute - if item.Key.Type == v3.AttributeKeyTypeResource { + if item.Key.Type == v3.AttributeKeyTypeResource || item.Key.Type == v3.AttributeKetTypeSpanSearchScope { continue } @@ -213,6 +213,28 @@ func orderByAttributeKeyTags(panelType v3.PanelType, items []v3.OrderBy, tags [] return str } +func buildSpanScopeQuery(fs *v3.FilterSet) (string, error) { + var query string + if fs == nil || len(fs.Items) == 0 { + return "", nil + } + for _, item := range fs.Items { + // skip anything other than resource attribute + if item.Key.Type != v3.AttributeKetTypeSpanSearchScope { + continue + } + keyName := item.Key.Key + if keyName == constants.SpanSearchScopeRoot { + query = "parent_span_id = '' " + } else if keyName == constants.SpanSearchScopeEntryPoint { + query = "((name, `serviceName`) IN ( SELECT DISTINCT name, serviceName from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_TOP_LEVEL_OPERATIONS_TABLENAME + " )) " + } else { + return "", fmt.Errorf("invalid scope item type: %s", item.Key.Type) + } + } + return query, nil +} + func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, panelType v3.PanelType, options v3.QBOptions) (string, error) { tracesStart := utils.GetEpochNanoSecs(start) tracesEnd := utils.GetEpochNanoSecs(end) @@ -248,6 +270,11 @@ func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, panelType v3. filterSubQuery = filterSubQuery + " AND (resource_fingerprint GLOBAL IN " + resourceSubQuery + ")" } + spanScopeSubQuery, err := buildSpanScopeQuery(mq.Filters) + if spanScopeSubQuery != "" { + filterSubQuery = filterSubQuery + " AND " + spanScopeSubQuery + } + // timerange will be sent in epoch millisecond selectLabels := getSelectLabels(mq.GroupBy) if selectLabels != "" { @@ -275,17 +302,9 @@ func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, panelType v3. return "", fmt.Errorf("select columns cannot be empty for panelType %s", panelType) } selectLabels = getSelectLabels(mq.SelectColumns) - 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) - } + // 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 { return "", fmt.Errorf("unsupported aggregate operator %s for panelType %s", mq.AggregateOperator, panelType) } diff --git a/pkg/query-service/constants/constants.go b/pkg/query-service/constants/constants.go index 13952b20595..f4bf2adfbf3 100644 --- a/pkg/query-service/constants/constants.go +++ b/pkg/query-service/constants/constants.go @@ -54,6 +54,9 @@ const DurationSort = "DurationSort" const TimestampSort = "TimestampSort" const PreferRPM = "PreferRPM" +const SpanSearchScopeRoot = "isRoot" +const SpanSearchScopeEntryPoint = "isEntryPoint" + func GetAlertManagerApiPrefix() string { if os.Getenv("ALERTMANAGER_API_PREFIX") != "" { return os.Getenv("ALERTMANAGER_API_PREFIX") diff --git a/pkg/query-service/model/v3/v3.go b/pkg/query-service/model/v3/v3.go index 9aa52bd9da9..d0d08178441 100644 --- a/pkg/query-service/model/v3/v3.go +++ b/pkg/query-service/model/v3/v3.go @@ -31,26 +31,6 @@ 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 ( @@ -342,6 +322,7 @@ const ( AttributeKeyTypeTag AttributeKeyType = "tag" AttributeKeyTypeResource AttributeKeyType = "resource" AttributeKeyTypeInstrumentationScope AttributeKeyType = "scope" + AttributeKetTypeSpanSearchScope AttributeKeyType = "spanSearchScope" ) func (t AttributeKeyType) String() string { @@ -806,7 +787,6 @@ 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"` From 6ea3a32c1371a4ed8c4d29e6aad304d0853cc1f1 Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 20 Jan 2025 15:29:01 +0530 Subject: [PATCH 04/11] feat: add search span scope in the list view tab to add the scope at per query level --- .../app/traces/v4/query_builder_test.go | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/pkg/query-service/app/traces/v4/query_builder_test.go b/pkg/query-service/app/traces/v4/query_builder_test.go index e6c6ef2082b..a9b055b67f5 100644 --- a/pkg/query-service/app/traces/v4/query_builder_test.go +++ b/pkg/query-service/app/traces/v4/query_builder_test.go @@ -552,40 +552,6 @@ func Test_buildTracesQuery(t *testing.T) { want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) order by timestamp ASC", }, - { - name: "test noop list view with entry_point_spans", - args: args{ - panelType: v3.PanelTypeList, - start: 1680066360726210000, - end: 1680066458000000000, - mq: &v3.BuilderQuery{ - AggregateOperator: v3.AggregateOperatorNoOp, - SpanSearchScope: v3.SpanSearchScopeEntryPoint, - Filters: &v3.FilterSet{}, - SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, - OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, - }, - }, - want: "SELECT timestamp as timestamp_datetime, span_id, trace_id, name as `name` from signoz_traces.distributed_signoz_index_v3 where ((name, `resource_string_service$$name`) IN ( SELECT DISTINCT name, serviceName from signoz_traces.distributed_top_level_operations )) and (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + - "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) order by timestamp ASC", - }, - { - name: "test noop list view with root_spans", - args: args{ - panelType: v3.PanelTypeList, - start: 1680066360726210000, - end: 1680066458000000000, - mq: &v3.BuilderQuery{ - AggregateOperator: v3.AggregateOperatorNoOp, - SpanSearchScope: v3.SpanSearchScopeRoot, - Filters: &v3.FilterSet{}, - SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, - OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, - }, - }, - want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where parent_span_id = '' AND (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + - "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) order by timestamp ASC", - }, { name: "test noop list view-without ts", args: args{ From 715af787f3ca9dc058300946e99a5970c0477e66 Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 20 Jan 2025 16:41:16 +0530 Subject: [PATCH 05/11] feat: add search span scope in the list view tab to add the scope at per query level --- pkg/query-service/app/traces/v4/query_builder.go | 7 ++++--- pkg/query-service/constants/constants.go | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/query-service/app/traces/v4/query_builder.go b/pkg/query-service/app/traces/v4/query_builder.go index 36ec587fde7..010504fbc42 100644 --- a/pkg/query-service/app/traces/v4/query_builder.go +++ b/pkg/query-service/app/traces/v4/query_builder.go @@ -219,15 +219,16 @@ func buildSpanScopeQuery(fs *v3.FilterSet) (string, error) { return "", nil } for _, item := range fs.Items { - // skip anything other than resource attribute + // skip anything other than Span Search scope attribute if item.Key.Type != v3.AttributeKetTypeSpanSearchScope { continue } - keyName := item.Key.Key + keyName := strings.ToLower(item.Key.Key) + if keyName == constants.SpanSearchScopeRoot { query = "parent_span_id = '' " } else if keyName == constants.SpanSearchScopeEntryPoint { - query = "((name, `serviceName`) IN ( SELECT DISTINCT name, serviceName from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_TOP_LEVEL_OPERATIONS_TABLENAME + " )) " + query = "((name, `resource_string_service$$name`) IN ( SELECT DISTINCT name, serviceName from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_TOP_LEVEL_OPERATIONS_TABLENAME + " )) " } else { return "", fmt.Errorf("invalid scope item type: %s", item.Key.Type) } diff --git a/pkg/query-service/constants/constants.go b/pkg/query-service/constants/constants.go index f4bf2adfbf3..373552e8719 100644 --- a/pkg/query-service/constants/constants.go +++ b/pkg/query-service/constants/constants.go @@ -54,8 +54,8 @@ const DurationSort = "DurationSort" const TimestampSort = "TimestampSort" const PreferRPM = "PreferRPM" -const SpanSearchScopeRoot = "isRoot" -const SpanSearchScopeEntryPoint = "isEntryPoint" +const SpanSearchScopeRoot = "isroot" +const SpanSearchScopeEntryPoint = "isentrypoint" func GetAlertManagerApiPrefix() string { if os.Getenv("ALERTMANAGER_API_PREFIX") != "" { From 09dea8dd8b5d780ce5c4f1d3ad7a6b59c53e0527 Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 20 Jan 2025 16:58:00 +0530 Subject: [PATCH 06/11] feat: add search span scope in the list view tab to add the scope at per query level --- .../app/traces/v4/query_builder_test.go | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkg/query-service/app/traces/v4/query_builder_test.go b/pkg/query-service/app/traces/v4/query_builder_test.go index a9b055b67f5..6897703f5cf 100644 --- a/pkg/query-service/app/traces/v4/query_builder_test.go +++ b/pkg/query-service/app/traces/v4/query_builder_test.go @@ -552,6 +552,38 @@ func Test_buildTracesQuery(t *testing.T) { want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) order by timestamp ASC", }, + { + name: "test noop list view with entry_point_spans", + args: args{ + panelType: v3.PanelTypeList, + start: 1680066360726210000, + end: 1680066458000000000, + mq: &v3.BuilderQuery{ + AggregateOperator: v3.AggregateOperatorNoOp, + Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{{Key: v3.AttributeKey{Key: "isEntryPoint", Type: v3.AttributeKetTypeSpanSearchScope, IsColumn: false}, Value: true, Operator: v3.FilterOperatorEqual}}}, + SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, + OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, + }, + }, + want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) AND ((name, `resource_string_service$$name`) IN ( SELECT DISTINCT name, serviceName from signoz_traces.distributed_top_level_operations )) order by timestamp ASC", + }, + { + name: "test noop list view with root_spans", + args: args{ + panelType: v3.PanelTypeList, + start: 1680066360726210000, + end: 1680066458000000000, + mq: &v3.BuilderQuery{ + AggregateOperator: v3.AggregateOperatorNoOp, + Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{{Key: v3.AttributeKey{Key: "isRoot", Type: v3.AttributeKetTypeSpanSearchScope, IsColumn: false}, Value: true, Operator: v3.FilterOperatorEqual}}}, + SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, + OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, + }, + }, + want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) AND parent_span_id = '' order by timestamp ASC", + }, { name: "test noop list view-without ts", args: args{ From a9959e07ebde6b7ae862ef25370e9dc81e7cb738 Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 20 Jan 2025 16:59:40 +0530 Subject: [PATCH 07/11] feat: add search span scope in the list view tab to add the scope at per query level --- pkg/query-service/app/traces/v4/query_builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/query-service/app/traces/v4/query_builder.go b/pkg/query-service/app/traces/v4/query_builder.go index 010504fbc42..b667f5163e9 100644 --- a/pkg/query-service/app/traces/v4/query_builder.go +++ b/pkg/query-service/app/traces/v4/query_builder.go @@ -93,7 +93,7 @@ func buildTracesFilterQuery(fs *v3.FilterSet) (string, error) { if fs != nil && len(fs.Items) != 0 { for _, item := range fs.Items { - // skip if it's a resource attribute + // skip if it's a resource attribute or Span search scope attribute if item.Key.Type == v3.AttributeKeyTypeResource || item.Key.Type == v3.AttributeKetTypeSpanSearchScope { continue } From 47d864fee9653819303d1dcf90314d051796e4d7 Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 20 Jan 2025 17:02:00 +0530 Subject: [PATCH 08/11] feat: add search span scope in the list view tab to add the scope at per query level --- pkg/query-service/app/traces/v4/query_builder.go | 4 ++-- pkg/query-service/app/traces/v4/query_builder_test.go | 4 ++-- pkg/query-service/model/v3/v3.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/query-service/app/traces/v4/query_builder.go b/pkg/query-service/app/traces/v4/query_builder.go index b667f5163e9..5f9551bf0af 100644 --- a/pkg/query-service/app/traces/v4/query_builder.go +++ b/pkg/query-service/app/traces/v4/query_builder.go @@ -94,7 +94,7 @@ func buildTracesFilterQuery(fs *v3.FilterSet) (string, error) { for _, item := range fs.Items { // skip if it's a resource attribute or Span search scope attribute - if item.Key.Type == v3.AttributeKeyTypeResource || item.Key.Type == v3.AttributeKetTypeSpanSearchScope { + if item.Key.Type == v3.AttributeKeyTypeResource || item.Key.Type == v3.AttributeKeyTypeSpanSearchScope { continue } @@ -220,7 +220,7 @@ func buildSpanScopeQuery(fs *v3.FilterSet) (string, error) { } for _, item := range fs.Items { // skip anything other than Span Search scope attribute - if item.Key.Type != v3.AttributeKetTypeSpanSearchScope { + if item.Key.Type != v3.AttributeKeyTypeSpanSearchScope { continue } keyName := strings.ToLower(item.Key.Key) diff --git a/pkg/query-service/app/traces/v4/query_builder_test.go b/pkg/query-service/app/traces/v4/query_builder_test.go index 6897703f5cf..1a1e77d4fa8 100644 --- a/pkg/query-service/app/traces/v4/query_builder_test.go +++ b/pkg/query-service/app/traces/v4/query_builder_test.go @@ -560,7 +560,7 @@ func Test_buildTracesQuery(t *testing.T) { end: 1680066458000000000, mq: &v3.BuilderQuery{ AggregateOperator: v3.AggregateOperatorNoOp, - Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{{Key: v3.AttributeKey{Key: "isEntryPoint", Type: v3.AttributeKetTypeSpanSearchScope, IsColumn: false}, Value: true, Operator: v3.FilterOperatorEqual}}}, + Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{{Key: v3.AttributeKey{Key: "isEntryPoint", Type: v3.AttributeKeyTypeSpanSearchScope, IsColumn: false}, Value: true, Operator: v3.FilterOperatorEqual}}}, SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, }, @@ -576,7 +576,7 @@ func Test_buildTracesQuery(t *testing.T) { end: 1680066458000000000, mq: &v3.BuilderQuery{ AggregateOperator: v3.AggregateOperatorNoOp, - Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{{Key: v3.AttributeKey{Key: "isRoot", Type: v3.AttributeKetTypeSpanSearchScope, IsColumn: false}, Value: true, Operator: v3.FilterOperatorEqual}}}, + Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{{Key: v3.AttributeKey{Key: "isRoot", Type: v3.AttributeKeyTypeSpanSearchScope, IsColumn: false}, Value: true, Operator: v3.FilterOperatorEqual}}}, SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, }, diff --git a/pkg/query-service/model/v3/v3.go b/pkg/query-service/model/v3/v3.go index 3cad752cc09..b9570fc52e4 100644 --- a/pkg/query-service/model/v3/v3.go +++ b/pkg/query-service/model/v3/v3.go @@ -322,7 +322,7 @@ const ( AttributeKeyTypeTag AttributeKeyType = "tag" AttributeKeyTypeResource AttributeKeyType = "resource" AttributeKeyTypeInstrumentationScope AttributeKeyType = "scope" - AttributeKetTypeSpanSearchScope AttributeKeyType = "spanSearchScope" + AttributeKeyTypeSpanSearchScope AttributeKeyType = "spanSearchScope" ) func (t AttributeKeyType) String() string { From 1f650e332466ec3fffb453b665312e6db1189d79 Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 20 Jan 2025 17:10:18 +0530 Subject: [PATCH 09/11] feat: add search span scope in the list view tab to add the scope at per query level --- .../app/traces/v4/query_builder_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/query-service/app/traces/v4/query_builder_test.go b/pkg/query-service/app/traces/v4/query_builder_test.go index 1a1e77d4fa8..0c3026f6552 100644 --- a/pkg/query-service/app/traces/v4/query_builder_test.go +++ b/pkg/query-service/app/traces/v4/query_builder_test.go @@ -584,6 +584,22 @@ func Test_buildTracesQuery(t *testing.T) { want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) AND parent_span_id = '' order by timestamp ASC", }, + { + name: "test noop list view with root_spans with other attributes", + args: args{ + panelType: v3.PanelTypeList, + start: 1680066360726210000, + end: 1680066458000000000, + mq: &v3.BuilderQuery{ + AggregateOperator: v3.AggregateOperatorNoOp, + Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{{Key: v3.AttributeKey{Key: "isRoot", Type: v3.AttributeKeyTypeSpanSearchScope, IsColumn: false}, Value: true, Operator: v3.FilterOperatorEqual}, {Key: v3.AttributeKey{Key: "service.name", Type: v3.AttributeKeyTypeResource, IsColumn: true, DataType: v3.AttributeKeyDataTypeString}, Value: "cartservice", Operator: v3.FilterOperatorEqual}}}, + SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, + OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, + }, + }, + want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) AND (resource_fingerprint GLOBAL IN (SELECT fingerprint FROM signoz_traces.distributed_traces_v3_resource WHERE (seen_at_ts_bucket_start >= 1680064560) AND (seen_at_ts_bucket_start <= 1680066458) AND simpleJSONExtractString(labels, 'service.name') = 'cartservice' AND labels like '%service.name%cartservice%')) AND parent_span_id = '' order by timestamp ASC", + }, { name: "test noop list view-without ts", args: args{ From bdaaabc782f134e92775e10b544558a47e259e6b Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 20 Jan 2025 17:17:33 +0530 Subject: [PATCH 10/11] feat: add search span scope in the list view tab to add the scope at per query level --- pkg/query-service/app/traces/v4/query_builder.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/query-service/app/traces/v4/query_builder.go b/pkg/query-service/app/traces/v4/query_builder.go index 5f9551bf0af..3f62540fe1d 100644 --- a/pkg/query-service/app/traces/v4/query_builder.go +++ b/pkg/query-service/app/traces/v4/query_builder.go @@ -227,13 +227,15 @@ func buildSpanScopeQuery(fs *v3.FilterSet) (string, error) { if keyName == constants.SpanSearchScopeRoot { query = "parent_span_id = '' " + return query, nil } else if keyName == constants.SpanSearchScopeEntryPoint { query = "((name, `resource_string_service$$name`) IN ( SELECT DISTINCT name, serviceName from " + constants.SIGNOZ_TRACE_DBNAME + "." + constants.SIGNOZ_TOP_LEVEL_OPERATIONS_TABLENAME + " )) " + return query, nil } else { return "", fmt.Errorf("invalid scope item type: %s", item.Key.Type) } } - return query, nil + return "", nil } func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, panelType v3.PanelType, options v3.QBOptions) (string, error) { From 89159a50e96fe6ce50329e5c960512772208547f Mon Sep 17 00:00:00 2001 From: eKuG Date: Mon, 20 Jan 2025 17:19:39 +0530 Subject: [PATCH 11/11] feat: add search span scope in the list view tab to add the scope at per query level --- .../app/traces/v4/query_builder_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/query-service/app/traces/v4/query_builder_test.go b/pkg/query-service/app/traces/v4/query_builder_test.go index 0c3026f6552..50b83fa9d94 100644 --- a/pkg/query-service/app/traces/v4/query_builder_test.go +++ b/pkg/query-service/app/traces/v4/query_builder_test.go @@ -584,6 +584,22 @@ func Test_buildTracesQuery(t *testing.T) { want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) AND parent_span_id = '' order by timestamp ASC", }, + { + name: "test noop list view with root_spans and entry_point_spans both existing", + args: args{ + panelType: v3.PanelTypeList, + start: 1680066360726210000, + end: 1680066458000000000, + mq: &v3.BuilderQuery{ + AggregateOperator: v3.AggregateOperatorNoOp, + Filters: &v3.FilterSet{Operator: "AND", Items: []v3.FilterItem{{Key: v3.AttributeKey{Key: "isRoot", Type: v3.AttributeKeyTypeSpanSearchScope, IsColumn: false}, Value: true, Operator: v3.FilterOperatorEqual}, {Key: v3.AttributeKey{Key: "isEntryPoint", Type: v3.AttributeKeyTypeSpanSearchScope, IsColumn: false}, Value: true, Operator: v3.FilterOperatorEqual}}}, + SelectColumns: []v3.AttributeKey{{Key: "name", DataType: v3.AttributeKeyDataTypeString, Type: v3.AttributeKeyTypeTag, IsColumn: true}}, + OrderBy: []v3.OrderBy{{ColumnName: "timestamp", Order: "ASC"}}, + }, + }, + want: "SELECT timestamp as timestamp_datetime, spanID, traceID, name as `name` from signoz_traces.distributed_signoz_index_v3 where (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " + + "AND (ts_bucket_start >= 1680064560 AND ts_bucket_start <= 1680066458) AND parent_span_id = '' order by timestamp ASC", + }, { name: "test noop list view with root_spans with other attributes", args: args{