Skip to content

Commit

Permalink
[chore] fix exhaustive lint for prometheus receiver (open-telemetry#2…
Browse files Browse the repository at this point in the history
…4237)

Description:
related open-telemetry#23266

Signed-off-by: Ziqi Zhao <[email protected]>
Co-authored-by: Alex Boten <[email protected]>
  • Loading branch information
fatsheep9146 and Alex Boten committed Jul 12, 2023
1 parent 5d6027f commit f88e0d6
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions receiver/prometheusreceiver/internal/metricfamily.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ func (mf *metricFamily) addSeries(seriesRef uint64, metricName string, ls labels
} else {
mg.value = v
}
case pmetric.MetricTypeEmpty, pmetric.MetricTypeGauge, pmetric.MetricTypeExponentialHistogram:
fallthrough
default:
mg.value = v
}
Expand Down Expand Up @@ -336,6 +338,8 @@ func (mf *metricFamily) appendMetric(metrics pmetric.MetricSlice, normalizer *pr
}
pointCount = sdpL.Len()

case pmetric.MetricTypeEmpty, pmetric.MetricTypeGauge, pmetric.MetricTypeExponentialHistogram:
fallthrough
default: // Everything else should be set to a Gauge.
gauge := metric.SetEmptyGauge()
gdpL := gauge.DataPoints()
Expand Down
3 changes: 3 additions & 0 deletions receiver/prometheusreceiver/internal/metrics_adjuster.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ func (a *initialPointAdjuster) AdjustMetrics(metrics pmetric.Metrics) error {
case pmetric.MetricTypeSum:
a.adjustMetricSum(tsm, metric)

case pmetric.MetricTypeEmpty, pmetric.MetricTypeExponentialHistogram:
fallthrough

default:
// this shouldn't happen
a.logger.Info("Adjust - skipping unexpected point", zap.String("type", dataType.String()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ service:
switch state {
case otelcol.StateRunning, otelcol.StateClosed, otelcol.StateClosing:
notYetStarted = false
case otelcol.StateStarting:
}
time.Sleep(10 * time.Millisecond)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (stma *startTimeMetricAdjuster) AdjustMetrics(metrics pmetric.Metrics) erro
dp.SetStartTimestamp(startTimeTs)
}

case pmetric.MetricTypeEmpty, pmetric.MetricTypeExponentialHistogram:
fallthrough

default:
stma.logger.Warn("Unknown metric type", zap.String("type", metric.Type().String()))
}
Expand Down Expand Up @@ -99,6 +102,8 @@ func (stma *startTimeMetricAdjuster) getStartTime(metrics pmetric.Metrics) (floa
}
return metric.Sum().DataPoints().At(0).DoubleValue(), nil

case pmetric.MetricTypeEmpty, pmetric.MetricTypeHistogram, pmetric.MetricTypeExponentialHistogram, pmetric.MetricTypeSummary:
fallthrough
default:
return 0, errUnsupportedTypeStartTimeMetric
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func TestStartTimeMetricMatch(t *testing.T) {
for l := 0; l < dps.Len(); l++ {
assert.Equal(t, tt.expectedStartTime, dps.At(l).StartTimestamp())
}
case pmetric.MetricTypeEmpty, pmetric.MetricTypeGauge, pmetric.MetricTypeExponentialHistogram:
}
}
}
Expand Down
1 change: 1 addition & 0 deletions receiver/prometheusreceiver/internal/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ func (s *startTimeAdjuster) AdjustMetrics(metrics pmetric.Metrics) error {
for l := 0; l < dps.Len(); l++ {
dps.At(l).SetStartTimestamp(s.startTime)
}
case pmetric.MetricTypeEmpty, pmetric.MetricTypeGauge, pmetric.MetricTypeExponentialHistogram:
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions receiver/prometheusreceiver/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func getSortedNotUsefulLabels(mType pmetric.MetricType) []string {
return notUsefulLabelsHistogram
case pmetric.MetricTypeSummary:
return notUsefulLabelsSummary
case pmetric.MetricTypeEmpty, pmetric.MetricTypeGauge, pmetric.MetricTypeSum, pmetric.MetricTypeExponentialHistogram:
fallthrough
default:
return notUsefulLabelsOther
}
Expand Down Expand Up @@ -84,6 +86,8 @@ func getBoundary(metricType pmetric.MetricType, labels labels.Labels) (float64,
if val == "" {
return 0, errEmptyQuantileLabel
}
case pmetric.MetricTypeEmpty, pmetric.MetricTypeGauge, pmetric.MetricTypeSum, pmetric.MetricTypeExponentialHistogram:
fallthrough
default:
return 0, errNoBoundaryLabel
}
Expand All @@ -110,6 +114,8 @@ func convToMetricType(metricType textparse.MetricType) (pmetric.MetricType, bool
return pmetric.MetricTypeSummary, true
case textparse.MetricTypeInfo, textparse.MetricTypeStateset:
return pmetric.MetricTypeSum, false
case textparse.MetricTypeGaugeHistogram:
fallthrough
default:
// including: textparse.MetricTypeGaugeHistogram
return pmetric.MetricTypeEmpty, false
Expand Down
3 changes: 3 additions & 0 deletions receiver/prometheusreceiver/metrics_receiver_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func isFirstFailedScrape(metrics []pmetric.Metric, normalizedNames bool) bool {
return false
}
}
case pmetric.MetricTypeEmpty, pmetric.MetricTypeExponentialHistogram:
}
}
return true
Expand Down Expand Up @@ -401,6 +402,7 @@ func assertMetricPresent(name string, metricTypeExpectations metricTypeComparato
require.Equal(t, m.Summary().DataPoints().Len(), len(dataPointExpectations), "Expected number of data-points in Summary metric '%s' does not match to testdata", name)
spc(t, m.Summary().DataPoints().At(i))
}
case pmetric.MetricTypeEmpty, pmetric.MetricTypeExponentialHistogram:
}
}
}
Expand Down Expand Up @@ -672,6 +674,7 @@ func getTS(ms pmetric.MetricSlice) pcommon.Timestamp {
return m.Summary().DataPoints().At(0).Timestamp()
case pmetric.MetricTypeExponentialHistogram:
return m.ExponentialHistogram().DataPoints().At(0).Timestamp()
case pmetric.MetricTypeEmpty:
}
return 0
}
1 change: 1 addition & 0 deletions receiver/prometheusreceiver/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ func verifyStartTimeMetricPage(t *testing.T, td *testData, result []pmetric.Reso
assert.Equal(t, timestamp.AsTime(), metrics[i].Summary().DataPoints().At(j).StartTimestamp().AsTime())
numTimeseries++
}
case pmetric.MetricTypeEmpty, pmetric.MetricTypeExponentialHistogram:
}
}
assert.Equal(t, numStartTimeMetricPageTimeseries, numTimeseries)
Expand Down

0 comments on commit f88e0d6

Please sign in to comment.