mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 08:35:54 +08:00
chore: add cluster, nodes that are sending incorrect host metrics (#6969)
This commit is contained in:
parent
d0eefa0cf2
commit
88084af4d4
@ -15,6 +15,7 @@ import (
|
|||||||
"go.signoz.io/signoz/pkg/query-service/model"
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
v3 "go.signoz.io/signoz/pkg/query-service/model/v3"
|
||||||
"go.signoz.io/signoz/pkg/query-service/postprocess"
|
"go.signoz.io/signoz/pkg/query-service/postprocess"
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -332,23 +333,53 @@ func (h *HostsRepo) DidSendHostMetricsData(ctx context.Context, req model.HostLi
|
|||||||
return count > 0, nil
|
return count > 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HostsRepo) IsSendingK8SAgentMetrics(ctx context.Context, req model.HostListRequest) (bool, error) {
|
func (h *HostsRepo) IsSendingK8SAgentMetrics(ctx context.Context, req model.HostListRequest) ([]string, []string, error) {
|
||||||
names := []string{}
|
names := []string{}
|
||||||
for _, metricName := range metricNamesForHosts {
|
for _, metricName := range metricNamesForHosts {
|
||||||
names = append(names, metricName)
|
names = append(names, metricName)
|
||||||
}
|
}
|
||||||
namesStr := "'" + strings.Join(names, "','") + "'"
|
namesStr := "'" + strings.Join(names, "','") + "'"
|
||||||
|
|
||||||
|
queryForRecentFingerprints := fmt.Sprintf(`
|
||||||
|
SELECT DISTINCT fingerprint
|
||||||
|
FROM %s.%s
|
||||||
|
WHERE metric_name IN (%s)
|
||||||
|
AND unix_milli >= toUnixTimestamp(now() - INTERVAL 5 MINUTE) * 1000`,
|
||||||
|
constants.SIGNOZ_METRIC_DBNAME, constants.SIGNOZ_SAMPLES_V4_TABLENAME, namesStr)
|
||||||
|
|
||||||
query := fmt.Sprintf(`
|
query := fmt.Sprintf(`
|
||||||
SELECT count()
|
SELECT DISTINCT JSONExtractString(labels, 'k8s_cluster_name') as k8s_cluster_name, JSONExtractString(labels, 'k8s_node_name') as k8s_node_name
|
||||||
FROM %s.%s
|
FROM %s.%s
|
||||||
WHERE metric_name IN (%s)
|
WHERE metric_name IN (%s)
|
||||||
AND unix_milli >= toUnixTimestamp(now() - INTERVAL 60 MINUTE) * 1000
|
AND unix_milli >= toUnixTimestamp(now() - INTERVAL 60 MINUTE) * 1000
|
||||||
AND JSONExtractString(labels, 'host_name') LIKE '%%-otel-agent%%'`,
|
AND JSONExtractString(labels, 'host_name') LIKE '%%-otel-agent%%'
|
||||||
constants.SIGNOZ_METRIC_DBNAME, constants.SIGNOZ_TIMESERIES_V4_TABLENAME, namesStr)
|
AND fingerprint GLOBAL IN (%s)`,
|
||||||
|
constants.SIGNOZ_METRIC_DBNAME, constants.SIGNOZ_TIMESERIES_V4_TABLENAME, namesStr, queryForRecentFingerprints)
|
||||||
|
|
||||||
count, err := h.reader.GetCountOfThings(ctx, query)
|
result, err := h.reader.GetListResultV3(ctx, query)
|
||||||
return count > 0, err
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
clusterNames := make(map[string]struct{})
|
||||||
|
nodeNames := make(map[string]struct{})
|
||||||
|
|
||||||
|
for _, row := range result {
|
||||||
|
switch v := row.Data["k8s_cluster_name"].(type) {
|
||||||
|
case string:
|
||||||
|
clusterNames[v] = struct{}{}
|
||||||
|
case *string:
|
||||||
|
clusterNames[*v] = struct{}{}
|
||||||
|
}
|
||||||
|
switch v := row.Data["k8s_node_name"].(type) {
|
||||||
|
case string:
|
||||||
|
nodeNames[v] = struct{}{}
|
||||||
|
case *string:
|
||||||
|
nodeNames[*v] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return maps.Keys(clusterNames), maps.Keys(nodeNames), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HostsRepo) GetHostList(ctx context.Context, req model.HostListRequest) (model.HostListResponse, error) {
|
func (h *HostsRepo) GetHostList(ctx context.Context, req model.HostListRequest) (model.HostListResponse, error) {
|
||||||
@ -372,8 +403,10 @@ func (h *HostsRepo) GetHostList(ctx context.Context, req model.HostListRequest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// don't fail the request if we can't get these values
|
// don't fail the request if we can't get these values
|
||||||
if sendingK8SAgentMetrics, err := h.IsSendingK8SAgentMetrics(ctx, req); err == nil {
|
if clusterNames, nodeNames, err := h.IsSendingK8SAgentMetrics(ctx, req); err == nil {
|
||||||
resp.IsSendingK8SAgentMetrics = sendingK8SAgentMetrics
|
resp.IsSendingK8SAgentMetrics = len(clusterNames) > 0 || len(nodeNames) > 0
|
||||||
|
resp.ClusterNames = clusterNames
|
||||||
|
resp.NodeNames = nodeNames
|
||||||
}
|
}
|
||||||
if sentAnyHostMetricsData, err := h.DidSendHostMetricsData(ctx, req); err == nil {
|
if sentAnyHostMetricsData, err := h.DidSendHostMetricsData(ctx, req); err == nil {
|
||||||
resp.SentAnyHostMetricsData = sentAnyHostMetricsData
|
resp.SentAnyHostMetricsData = sentAnyHostMetricsData
|
||||||
|
@ -42,6 +42,8 @@ type HostListResponse struct {
|
|||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
SentAnyHostMetricsData bool `json:"sentAnyHostMetricsData"`
|
SentAnyHostMetricsData bool `json:"sentAnyHostMetricsData"`
|
||||||
IsSendingK8SAgentMetrics bool `json:"isSendingK8SAgentMetrics"`
|
IsSendingK8SAgentMetrics bool `json:"isSendingK8SAgentMetrics"`
|
||||||
|
ClusterNames []string `json:"clusterNames"`
|
||||||
|
NodeNames []string `json:"nodeNames"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *HostListResponse) SortBy(orderBy *v3.OrderBy) {
|
func (r *HostListResponse) SortBy(orderBy *v3.OrderBy) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user