mirror of
https://github.com/ccfos/nightingale.git
synced 2026-03-04 06:59:00 +00:00
Compare commits
2 Commits
optimize-c
...
v6.7.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07c602660a | ||
|
|
c674646c57 |
@@ -173,9 +173,13 @@ func (p *Processor) BuildEvent(anomalyPoint common.AnomalyPoint, from string, no
|
||||
dsName = ds.Name
|
||||
}
|
||||
|
||||
bg := p.BusiGroupCache.GetByBusiGroupId(p.rule.GroupId)
|
||||
|
||||
event := p.rule.GenerateNewEvent(p.ctx)
|
||||
|
||||
bg := p.BusiGroupCache.GetByBusiGroupId(p.rule.GroupId)
|
||||
if bg != nil {
|
||||
event.GroupName = bg.Name
|
||||
}
|
||||
|
||||
event.TriggerTime = anomalyPoint.Timestamp
|
||||
event.TagsMap = p.tagsMap
|
||||
event.DatasourceId = p.datasourceId
|
||||
@@ -186,7 +190,6 @@ func (p *Processor) BuildEvent(anomalyPoint common.AnomalyPoint, from string, no
|
||||
event.TriggerValue = anomalyPoint.ReadableValue()
|
||||
event.TriggerValues = anomalyPoint.Values
|
||||
event.TagsJSON = p.tagsArr
|
||||
event.GroupName = bg.Name
|
||||
event.Tags = strings.Join(p.tagsArr, ",,")
|
||||
event.IsRecovered = false
|
||||
event.Callbacks = p.rule.Callbacks
|
||||
|
||||
@@ -21,9 +21,9 @@ func extractMetricFromTimeSeries(s *prompb.TimeSeries) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func extractIdentFromTimeSeries(s *prompb.TimeSeries, ignoreIdent bool, identMetrics []string) string {
|
||||
func extractIdentFromTimeSeries(s *prompb.TimeSeries, ignoreIdent bool, identMetrics []string) (string, string) {
|
||||
if s == nil {
|
||||
return ""
|
||||
return "", ""
|
||||
}
|
||||
|
||||
labelMap := make(map[string]int)
|
||||
@@ -32,6 +32,7 @@ func extractIdentFromTimeSeries(s *prompb.TimeSeries, ignoreIdent bool, identMet
|
||||
}
|
||||
|
||||
var ident string
|
||||
var heartbeatIdent string
|
||||
// agent_hostname for grafana-agent and categraf
|
||||
if idx, ok := labelMap["agent_hostname"]; ok {
|
||||
s.Labels[idx].Name = "ident"
|
||||
@@ -46,6 +47,11 @@ func extractIdentFromTimeSeries(s *prompb.TimeSeries, ignoreIdent bool, identMet
|
||||
}
|
||||
}
|
||||
|
||||
if idx, ok := labelMap["ident"]; ok {
|
||||
ident = s.Labels[idx].Value
|
||||
}
|
||||
|
||||
heartbeatIdent = ident
|
||||
if len(identMetrics) > 0 {
|
||||
metricFound := false
|
||||
for _, identMetric := range identMetrics {
|
||||
@@ -56,15 +62,11 @@ func extractIdentFromTimeSeries(s *prompb.TimeSeries, ignoreIdent bool, identMet
|
||||
}
|
||||
|
||||
if !metricFound {
|
||||
return ""
|
||||
heartbeatIdent = ""
|
||||
}
|
||||
}
|
||||
|
||||
if idx, ok := labelMap["ident"]; ok {
|
||||
ident = s.Labels[idx].Value
|
||||
}
|
||||
|
||||
return ident
|
||||
return ident, heartbeatIdent
|
||||
}
|
||||
|
||||
func duplicateLabelKey(series *prompb.TimeSeries) bool {
|
||||
@@ -99,22 +101,15 @@ func (rt *Router) remoteWrite(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
ident string
|
||||
ids = make(map[string]struct{})
|
||||
)
|
||||
var ids = make(map[string]struct{})
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
if duplicateLabelKey(&req.Timeseries[i]) {
|
||||
continue
|
||||
}
|
||||
|
||||
ident = extractIdentFromTimeSeries(&req.Timeseries[i], ginx.QueryBool(c, "ignore_ident", false), rt.Pushgw.IdentMetrics)
|
||||
ident, heartbeatIdent := extractIdentFromTimeSeries(&req.Timeseries[i], ginx.QueryBool(c, "ignore_ident", false), rt.Pushgw.IdentMetrics)
|
||||
if len(ident) > 0 {
|
||||
// has ident tag or agent_hostname tag
|
||||
// register host in table target
|
||||
ids[ident] = struct{}{}
|
||||
|
||||
// enrich host labels
|
||||
target, has := rt.TargetCache.Get(ident)
|
||||
if has {
|
||||
@@ -122,6 +117,12 @@ func (rt *Router) remoteWrite(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(heartbeatIdent) > 0 {
|
||||
// has ident tag or agent_hostname tag
|
||||
// register host in table target
|
||||
ids[ident] = struct{}{}
|
||||
}
|
||||
|
||||
if len(ident) > 0 {
|
||||
rt.ForwardByIdent(c.ClientIP(), ident, &req.Timeseries[i])
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user