Skip to content

Commit

Permalink
[prometheusremotewriteexporter] don't add target info when it would o…
Browse files Browse the repository at this point in the history
…nly contain job and instance (#12768)
  • Loading branch information
dashpole committed Aug 19, 2022
1 parent e667631 commit 4e763e8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
17 changes: 9 additions & 8 deletions pkg/translator/prometheusremotewrite/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,6 @@ func addSingleSummaryDataPoint(pt pmetric.SummaryDataPoint, resource pcommon.Res

// addResourceTargetInfo converts the resource to the target info metric
func addResourceTargetInfo(resource pcommon.Resource, settings Settings, timestamp pcommon.Timestamp, tsMap map[string]*prompb.TimeSeries) {
if resource.Attributes().Len() == 0 {
return
}
// create parameters for addSample
name := targetMetricName
if len(settings.Namespace) > 0 {
name = settings.Namespace + "_" + name
}
// Use resource attributes (other than those used for job+instance) as the
// metric labels for the target info metric
attributes := pcommon.NewMap()
Expand All @@ -515,6 +507,15 @@ func addResourceTargetInfo(resource pcommon.Resource, settings Settings, timesta
return false
}
})
if attributes.Len() == 0 {
// If we only have job + instance, then target_info isn't useful, so don't add it.
return
}
// create parameters for addSample
name := targetMetricName
if len(settings.Namespace) > 0 {
name = settings.Namespace + "_" + name
}
labels := createAttributes(resource, attributes, settings.ExternalLabels, nameStr, name)
sample := &prompb.Sample{
Value: float64(1),
Expand Down
10 changes: 9 additions & 1 deletion pkg/translator/prometheusremotewrite/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,12 @@ func TestAddResourceTargetInfo(t *testing.T) {
conventions.AttributeServiceName: "service-name",
conventions.AttributeServiceNamespace: "service-namespace",
conventions.AttributeServiceInstanceID: "service-instance-id",
"resource_attr": "resource-attr-val-1",
}
resourceWithServiceAttrs := pcommon.NewResource()
pcommon.NewMapFromRaw(resourceAttrMap).CopyTo(resourceWithServiceAttrs.Attributes())
resourceWithServiceAttrs.Attributes().UpsertString("resource_attr", "resource-attr-val-1")
resourceWithOnlyServiceAttrs := pcommon.NewResource()
pcommon.NewMapFromRaw(resourceAttrMap).CopyTo(resourceWithOnlyServiceAttrs.Attributes())
for _, tc := range []struct {
desc string
resource pcommon.Resource
Expand Down Expand Up @@ -557,6 +559,12 @@ func TestAddResourceTargetInfo(t *testing.T) {
},
},
},
{
desc: "with resource, with only service attributes",
resource: resourceWithOnlyServiceAttrs,
timestamp: testdata.TestMetricStartTimestamp,
expected: map[string]*prompb.TimeSeries{},
},
} {
t.Run(tc.desc, func(t *testing.T) {
tsMap := map[string]*prompb.TimeSeries{}
Expand Down
16 changes: 16 additions & 0 deletions unreleased/prw-exporter-target_info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: prometheusremotewriteexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Don't emit the target_info metric when it would only contain job and instance

# One or more tracking issues related to the change
issues: [12768]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

0 comments on commit 4e763e8

Please sign in to comment.