Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/7077 | Related metrics api #7149

Open
wants to merge 36 commits into
base: feat/7080
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f6ac729
feat(summary view): added metric details apis | 7082
aniketio-ctrl Feb 11, 2025
9385029
feat(summary view): added metric details apis | 7082
aniketio-ctrl Feb 11, 2025
0ca886e
feat(summary view): added list metric details apis | 7084
aniketio-ctrl Feb 11, 2025
bab1399
feat(summary view): added tree map metric details apis | 7087
aniketio-ctrl Feb 11, 2025
9676b7e
feat(summary view): added list metric details apis | 7084
aniketio-ctrl Feb 12, 2025
969d6b0
feat(summary): updated contribution queries for metric metadata| 7082
aniketio-ctrl Feb 13, 2025
2a53b95
Merge branch 'feat/7080' of github.com:SigNoz/signoz into feat/7082
aniketio-ctrl Feb 13, 2025
51794ba
Merge branch 'feat/7082' of github.com:SigNoz/signoz into feat/7084
aniketio-ctrl Feb 13, 2025
d4bdcb1
feat(summary): added which table to use functions| 7084
aniketio-ctrl Feb 13, 2025
03d9c62
feat(summary): added clickhouse settings| 7084
aniketio-ctrl Feb 16, 2025
bba49c1
Merge branch 'feat/7084' of github.com:SigNoz/signoz into feat/7087
aniketio-ctrl Feb 16, 2025
3e43a96
feat(summary): added clickhouse settings| 7087
aniketio-ctrl Feb 16, 2025
7394c06
feat(summary): added clickhouse queries| 7082
aniketio-ctrl Feb 16, 2025
43a3122
feat(explorer): added clickhouse queries| 7077
aniketio-ctrl Feb 16, 2025
8149bb5
feat(explorer): added clickhouse queries| 7077
aniketio-ctrl Feb 17, 2025
d83daa6
feat(summary): removed cardinality from metadata | 7082
aniketio-ctrl Feb 17, 2025
a41d413
Merge branch 'feat/7082' of github.com:SigNoz/signoz into feat/7084
aniketio-ctrl Feb 17, 2025
08b9e9b
feat(summary): updated list metrics api into two parts| 7084
aniketio-ctrl Feb 17, 2025
4590195
feat(summary): added default values for list api| 7084
aniketio-ctrl Feb 17, 2025
e7269bb
Merge branch 'feat/7084' of github.com:SigNoz/signoz into feat/7087
aniketio-ctrl Feb 17, 2025
ea4c7ac
feat(summary): updated tree map samples query into two parts| 7087
aniketio-ctrl Feb 18, 2025
c1f86b1
feat(summary): updated tree map samples query into two parts| 7087
aniketio-ctrl Feb 18, 2025
bc61850
Merge branch 'feat/7087' of github.com:SigNoz/signoz into feat/7077_1
aniketio-ctrl Feb 18, 2025
c5459f3
feat(explorer): updated related metrics query| 7077
aniketio-ctrl Feb 18, 2025
e2ccc5c
feat(explorer): added clickhouse max threads settings| 7077
aniketio-ctrl Feb 18, 2025
4809dc0
Merge branch 'feat/7080' of github.com:SigNoz/signoz into feat/7077_1
aniketio-ctrl Feb 18, 2025
d91e7c1
feat(explorer): added clickhouse max threads settings| 7077
aniketio-ctrl Feb 18, 2025
843d9e1
feat(explorer): added clickhouse max threads settings| 7077
aniketio-ctrl Feb 18, 2025
baebb13
feat(explorer): added clickhouse max threads settings| 7077
aniketio-ctrl Feb 18, 2025
a70cf32
feat(explorer): added query range with related metrics api| 7077
aniketio-ctrl Feb 19, 2025
211b0b9
feat(explorer): added distributed ts table and query builder| 7077
aniketio-ctrl Feb 20, 2025
c2bb82f
Merge branch 'feat/7077_1' of github.com:SigNoz/signoz into feat/7077_1
aniketio-ctrl Feb 20, 2025
e87753a
Merge branch 'feat/7080' into feat/7077_1
aniketio-ctrl Feb 20, 2025
bded71e
feat(explorer): improved clickhouse queries
aniketio-ctrl Feb 22, 2025
f094fb3
Merge branch 'feat/7077_1' of github.com:SigNoz/signoz into feat/7077_1
aniketio-ctrl Feb 22, 2025
ead25be
feat(explorer): improved clickhouse queries
aniketio-ctrl Feb 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions pkg/query-service/app/clickhouseReader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5310,33 +5310,31 @@ func (r *ClickHouseReader) GetMetricsDataPointsAndLastReceived(ctx context.Conte
return dataPoints, uint64(lastRecievedTimestamp), nil // Convert to uint64 before returning
}

func (r *ClickHouseReader) GetTotalTimeSeriesForMetricName(ctx context.Context, metricName string) (uint64, uint64, *model.ApiError) {
func (r *ClickHouseReader) GetTotalTimeSeriesForMetricName(ctx context.Context, metricName string) (uint64, *model.ApiError) {
query := fmt.Sprintf(`SELECT
uniq(arrayJoin(arrayMap(x -> x.2, arrayFilter(x -> NOT startsWith(x.1, '__'), JSONExtractKeysAndValuesRaw(labels))))) AS cardinality,
count(DISTINCT fingerprint) AS timeSeriesCount
FROM %s.%s
WHERE metric_name = ?;`, signozMetricDBName, signozTSTableNameV41Day)
WHERE metric_name = ?;`, signozMetricDBName, signozTSTableNameV41Week)
var timeSeriesCount uint64
var cardinality uint64
err := r.db.QueryRow(ctx, query, metricName).Scan(&timeSeriesCount, &cardinality)
err := r.db.QueryRow(ctx, query, metricName).Scan(&timeSeriesCount)
if err != nil {
return 0, 0, &model.ApiError{Typ: "ClickHouseError", Err: err}
return 0, &model.ApiError{Typ: "ClickHouseError", Err: err}
}
return timeSeriesCount, cardinality, nil
return timeSeriesCount, nil
}

func (r *ClickHouseReader) GetAttributesForMetricName(ctx context.Context, metricName string) (*[]metrics_explorer.Attribute, *model.ApiError) {
query := fmt.Sprintf(`
SELECT
kv.1 AS key,
arrayMap(x -> replaceAll(x, '"', ''), groupUniqArray(kv.2)) AS values,
arrayMap(x -> trim(BOTH '\"' FROM x), groupUniqArray(kv.2)) AS values,
length(groupUniqArray(kv.2)) AS valueCount
FROM %s.%s
ARRAY JOIN arrayFilter(x -> NOT startsWith(x.1, '__'), JSONExtractKeysAndValuesRaw(labels)) AS kv
WHERE metric_name = 'system_memory_usage'
WHERE metric_name = ?
GROUP BY kv.1
ORDER BY valueCount DESC;
`, signozMetricDBName, signozTSTableNameV41Day)
`, signozMetricDBName, signozTSTableNameV41Week)

rows, err := r.db.Query(ctx, query, metricName)
if err != nil {
Expand Down Expand Up @@ -5373,7 +5371,7 @@ ORDER BY valueCount DESC;

func (r *ClickHouseReader) GetActiveTimeSeriesForMetricName(ctx context.Context, metricName string, duration time.Duration) (uint64, *model.ApiError) {
milli := time.Now().Add(-duration).UnixMilli()
query := fmt.Sprintf("SELECT count(DISTINCT fingerprint) FROM %s.%s WHERE metric_name = '%s' and unix_milli >= ?", signozMetricDBName, signozTSTableNameV41Day, metricName)
query := fmt.Sprintf("SELECT count(DISTINCT fingerprint) FROM %s.%s WHERE metric_name = '%s' and unix_milli >= ?", signozMetricDBName, signozTSTableNameV4, metricName)
var timeSeries uint64
// Using QueryRow instead of Select since we're only expecting a single value
err := r.db.QueryRow(ctx, query, milli).Scan(&timeSeries)
Expand Down
5 changes: 2 additions & 3 deletions pkg/query-service/app/metricsexplorer/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,17 @@ func (receiver *SummaryService) GetMetricsSummary(ctx context.Context, metricNam

// Call 3: GetTotalTimeSeriesForMetricName
g.Go(func() error {
totalSeries, cardinality, err := receiver.reader.GetTotalTimeSeriesForMetricName(ctx, metricName)
totalSeries, err := receiver.reader.GetTotalTimeSeriesForMetricName(ctx, metricName)
if err != nil {
return err
}
metricDetailsDTO.TimeSeriesTotal = totalSeries
metricDetailsDTO.Cardinality = cardinality
return nil
})

// Call 4: GetActiveTimeSeriesForMetricName
g.Go(func() error {
activeSeries, err := receiver.reader.GetActiveTimeSeriesForMetricName(ctx, metricName, 30*time.Minute)
activeSeries, err := receiver.reader.GetActiveTimeSeriesForMetricName(ctx, metricName, 120*time.Minute)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/query-service/interfaces/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type Reader interface {
GetAllMetricFilterAttributeKeys(ctx context.Context, req *metrics_explorer.FilterKeyRequest, skipDotNames bool) (*[]v3.AttributeKey, *model.ApiError)

GetMetricsDataPointsAndLastReceived(ctx context.Context, metricName string) (uint64, uint64, *model.ApiError)
GetTotalTimeSeriesForMetricName(ctx context.Context, metricName string) (uint64, uint64, *model.ApiError)
GetTotalTimeSeriesForMetricName(ctx context.Context, metricName string) (uint64, *model.ApiError)
GetActiveTimeSeriesForMetricName(ctx context.Context, metricName string, duration time.Duration) (uint64, *model.ApiError)
GetAttributesForMetricName(ctx context.Context, metricName string) (*[]metrics_explorer.Attribute, *model.ApiError)

Expand Down
1 change: 0 additions & 1 deletion pkg/query-service/model/metrics_explorer/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ type MetricDetailsDTO struct {
Description string `json:"description"`
Type string `json:"type"`
Unit string `json:"unit"`
Cardinality uint64 `json:"cardinality"`
DataPoints uint64 `json:"dataPoints"`
TimeSeriesTotal uint64 `json:"timeSeriesTotal"`
TimeSeriesActive uint64 `json:"timeSeriesActive"`
Expand Down