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

chore: add additional info for host metrics onboarding #6529

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions pkg/query-service/app/clickhouseReader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3384,6 +3384,17 @@ func (r *ClickHouseReader) GetMetricMetadata(ctx context.Context, metricName, se
}, nil
}

// GetCountOfThings returns the count of things in the query
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
// This is a generic function that can be used to check if any data exists for a given query
func (r *ClickHouseReader) GetCountOfThings(ctx context.Context, query string) (uint64, error) {
srikanthccv marked this conversation as resolved.
Show resolved Hide resolved
var count uint64
err := r.db.QueryRow(ctx, query).Scan(&count)
if err != nil {
return 0, err
}
return count, nil
}

func (r *ClickHouseReader) GetLatestReceivedMetric(
ctx context.Context, metricNames []string,
) (*model.MetricStatus, *model.ApiError) {
Expand Down
49 changes: 49 additions & 0 deletions pkg/query-service/app/inframetrics/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package inframetrics

import (
"context"
"fmt"
"math"
"sort"
"strings"
"time"

"go.signoz.io/signoz/pkg/query-service/app/metrics/v4/helpers"
"go.signoz.io/signoz/pkg/query-service/common"
"go.signoz.io/signoz/pkg/query-service/constants"
"go.signoz.io/signoz/pkg/query-service/interfaces"
"go.signoz.io/signoz/pkg/query-service/model"
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
Expand Down Expand Up @@ -310,6 +312,45 @@ func (h *HostsRepo) getTopHostGroups(ctx context.Context, req model.HostListRequ
return topHostGroups, allHostGroups, nil
}

func (h *HostsRepo) DidSendHostMetricsData(ctx context.Context, req model.HostListRequest) (bool, error) {

names := []string{}
for _, metricName := range metricNamesForHosts {
names = append(names, metricName)
}

namesStr := "'" + strings.Join(names, "','") + "'"

query := fmt.Sprintf("SELECT count() FROM %s.%s WHERE metric_name IN (%s)",
constants.SIGNOZ_METRIC_DBNAME, constants.SIGNOZ_TIMESERIES_v4_1DAY_TABLENAME, namesStr)

count, err := h.reader.GetCountOfThings(ctx, query)
if err != nil {
return false, err
}

return count > 0, nil
}

func (h *HostsRepo) IsSendingK8SAgentMetrics(ctx context.Context, req model.HostListRequest) (bool, error) {
names := []string{}
for _, metricName := range metricNamesForHosts {
names = append(names, metricName)
}
namesStr := "'" + strings.Join(names, "','") + "'"

query := fmt.Sprintf(`
SELECT count()
FROM %s.%s
WHERE metric_name IN (%s)
AND unix_milli >= toUnixTimestamp(now() - INTERVAL 60 MINUTE) * 1000
AND JSONExtractString(labels, 'host_name') LIKE '%%-otel-agent%%'`,
constants.SIGNOZ_METRIC_DBNAME, constants.SIGNOZ_TIMESERIES_V4_TABLENAME, namesStr)

count, err := h.reader.GetCountOfThings(ctx, query)
return count > 0, err
}

func (h *HostsRepo) GetHostList(ctx context.Context, req model.HostListRequest) (model.HostListResponse, error) {
resp := model.HostListResponse{}

Expand All @@ -330,6 +371,14 @@ func (h *HostsRepo) GetHostList(ctx context.Context, req model.HostListRequest)
resp.Type = model.ResponseTypeGroupedList
}

// don't fail the request if we can't get these values
if sendingK8SAgentMetrics, err := h.IsSendingK8SAgentMetrics(ctx, req); err == nil {
resp.IsSendingK8SAgentMetrics = sendingK8SAgentMetrics
}
if sentAnyHostMetricsData, err := h.DidSendHostMetricsData(ctx, req); err == nil {
resp.SentAnyHostMetricsData = sentAnyHostMetricsData
}

step := int64(math.Max(float64(common.MinAllowedStepInterval(req.Start, req.End)), 60))

query := HostsTableListQuery.Clone()
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 @@ -243,6 +243,7 @@ const (
SIGNOZ_SPAN_INDEX_LOCAL_TABLENAME = "signoz_index_v2"
SIGNOZ_SPAN_INDEX_V3_LOCAL_TABLENAME = "signoz_index_v3"
SIGNOZ_TIMESERIES_v4_LOCAL_TABLENAME = "time_series_v4"
SIGNOZ_TIMESERIES_V4_TABLENAME = "distributed_time_series_v4"
SIGNOZ_TIMESERIES_v4_6HRS_LOCAL_TABLENAME = "time_series_v4_6hrs"
SIGNOZ_TIMESERIES_v4_1DAY_LOCAL_TABLENAME = "time_series_v4_1day"
SIGNOZ_TIMESERIES_v4_1WEEK_LOCAL_TABLENAME = "time_series_v4_1week"
Expand Down
2 changes: 2 additions & 0 deletions pkg/query-service/interfaces/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type Reader interface {
// Query Progress tracking helpers.
ReportQueryStartForProgressTracking(queryId string) (reportQueryFinished func(), err *model.ApiError)
SubscribeToQueryProgress(queryId string) (<-chan model.QueryProgress, func(), *model.ApiError)

GetCountOfThings(ctx context.Context, query string) (uint64, error)
}

type Querier interface {
Expand Down
8 changes: 5 additions & 3 deletions pkg/query-service/model/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ type HostListRecord struct {
}

type HostListResponse struct {
Type ResponseType `json:"type"`
Records []HostListRecord `json:"records"`
Total int `json:"total"`
Type ResponseType `json:"type"`
Records []HostListRecord `json:"records"`
Total int `json:"total"`
SentAnyHostMetricsData bool `json:"sentAnyHostMetricsData"`
IsSendingK8SAgentMetrics bool `json:"isSendingK8SAgentMetrics"`
}

func (r *HostListResponse) SortBy(orderBy *v3.OrderBy) {
Expand Down
Loading