Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1687 from grafana/ensure-metric-id-set
Browse files Browse the repository at this point in the history
Ensure that metric id is always set during kafka ingestion
  • Loading branch information
Dieterbe authored Feb 27, 2020
2 parents b78a563 + 6c06422 commit 27873c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/mt-gateway/ingest/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func prepareIngest(in []*schema.MetricData, toPublish []*schema.MetricData) ([]*
promDiscards.Add(m.OrgId, err.Error())
continue
}
m.SetId()
metricTimestamp = getMetricsTimestampStat(m.OrgId)
metricTimestamp.ValueUint32(uint32(m.Time))
toPublish = append(toPublish, m)
Expand Down
14 changes: 6 additions & 8 deletions publish/kafka/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,12 @@ func (m *mtPublisher) Publish(metrics []*schema.MetricData) error {

for _, metric := range metrics {
if metric.Interval == 0 {
if m.autoInterval {
_, s := m.schemas.Match(metric.Name, 0)
metric.Interval = s.Retentions.Rets[0].SecondsPerPoint
metric.SetId()
} else {
log.Error("interval is 0 but can't deduce interval automatically. this should never happen")
return errors.New("need to deduce interval but cannot")
}
log.Error("interval must be set before publishing")
return errors.New("interval must be set before publishing")
}
if metric.Id == "" {
log.Error("metric ID must be set before publishing")
return errors.New("metric ID must be set before publishing")
}

isMD := false
Expand Down
3 changes: 3 additions & 0 deletions publish/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ var (
)

type Publisher interface {
//Publish the given metrics.
//Requires that the metric interval and ID have been set
Publish(metrics []*schema.MetricData) error
//Type returns the type of system the Publisher publishes to
Type() string
}

Expand Down

0 comments on commit 27873c6

Please sign in to comment.