Skip to content

Commit

Permalink
Invert condition check in convertMetricKindToBoolIfSupported
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Dame <[email protected]>
  • Loading branch information
psx95 and damemi authored Jun 29, 2023
1 parent 777a342 commit f2df20f
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions exporter/collector/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,18 +971,16 @@ func (m *metricMapper) numberDataPointToValue(
// unsupported type or failure to meet constraints for conversion.
func (me *metricMapper) convertMetricKindToBoolIfSupported(point pmetric.NumberDataPoint, metricKind metricpb.MetricDescriptor_MetricKind, metricUnit string) (*monitoringpb.TypedValue, metricpb.MetricDescriptor_ValueType) {
boolUnitPresent := metricUnit == specialIntToBoolUnit
if !boolUnitPresent || metricKind != metricpb.MetricDescriptor_GAUGE || point.ValueType() != pmetric.NumberDataPointValueTypeInt {
// constraints for conversion failed - will not convert to boolean
if boolUnitPresent {
// indicates the user intentionally tried to convert to BOOL and failed
me.obs.log.Warn("Failed to interpret metric as BOOL. Attempted conversion on BOOL metrics are only supported on integer valued gauges", zap.Any("metric_kind", metricKind), zap.Any("value_type", point.ValueType()))
}
return nil, metricpb.MetricDescriptor_VALUE_TYPE_UNSPECIFIED
}
return &monitoringpb.TypedValue{Value: &monitoringpb.TypedValue_BoolValue{
BoolValue: point.IntValue() != 0,
}},
metricpb.MetricDescriptor_BOOL
if metricUnit == specialIntToBoolUnit {
if metricKind == metricpb.MetricDescriptor_GAUGE && point.ValueType() == pmetric.NumberDataPointValueTypeInt {
return &monitoringpb.TypedValue{Value: &monitoringpb.TypedValue_BoolValue{
BoolValue: point.IntValue() != 0,
}},
metricpb.MetricDescriptor_BOOL
}
me.obs.log.Warn("Failed to interpret metric as BOOL. Attempted conversion on BOOL metrics are only supported on integer valued gauges", zap.Any("metric_kind", metricKind), zap.Any("value_type", point.ValueType()))
}
return nil, metricpb.MetricDescriptor_VALUE_TYPE_UNSPECIFIED
}

func attributesToLabels(attrs pcommon.Map) labels {
Expand Down

0 comments on commit f2df20f

Please sign in to comment.