Skip to content

Commit

Permalink
fix(cloud): also replace url=name tag for netext.NetTrail
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mirić committed Nov 1, 2019
1 parent b01041d commit 484cafd
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions stats/cloud/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,42 @@ func (c *Collector) Run(ctx context.Context) {
}
}

func useCloudTags(source *httpext.Trail) *httpext.Trail {
name, nameExist := source.Tags.Get("name")
url, urlExist := source.Tags.Get("url")
// replaceTags overwrites the url tag to match the value of the name tag.
// See #1220.
func replaceTags(tags *stats.SampleTags) *stats.SampleTags {
name, nameExist := tags.Get("name")
url, urlExist := tags.Get("url")
if !nameExist || !urlExist || name == url {
return source
return tags
}

newTags := source.Tags.CloneTags()
newTags := tags.CloneTags()
newTags["url"] = name

return stats.IntoSampleTags(&newTags)
}

func replaceTagsHTTP(source *httpext.Trail) *httpext.Trail {
tags := replaceTags(source.Tags)
if tags == source.Tags {
return source
}
dest := new(httpext.Trail)
*dest = *source
dest.Tags = stats.IntoSampleTags(&newTags)
dest.Tags = tags
dest.Samples = nil
return dest
}

func replaceTagsNet(source *netext.NetTrail) *netext.NetTrail {
tags := replaceTags(source.Tags)
if tags == source.Tags {
return source
}
dest := new(netext.NetTrail)
*dest = *source
dest.Tags = tags
dest.Samples = nil
return dest
}

Expand All @@ -287,14 +308,17 @@ func (c *Collector) Collect(sampleContainers []stats.SampleContainer) {
for _, sampleContainer := range sampleContainers {
switch sc := sampleContainer.(type) {
case *httpext.Trail:
sc = useCloudTags(sc)
sc = replaceTagsHTTP(sc)

// Check if aggregation is enabled,
if c.config.AggregationPeriod.Duration > 0 {
newHTTPTrails = append(newHTTPTrails, sc)
} else {
newSamples = append(newSamples, NewSampleFromTrail(sc))
}
case *netext.NetTrail:
sc = replaceTagsNet(sc)

//TODO: aggregate?
values := map[string]float64{
metrics.DataSent.Name: float64(sc.BytesWritten),
Expand Down

0 comments on commit 484cafd

Please sign in to comment.