Skip to content

Commit

Permalink
[receiver/prometheus] Enable linters and fix issues (#11806)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski authored Jun 30, 2022
1 parent ca9f1b8 commit 877066b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
5 changes: 3 additions & 2 deletions receiver/prometheusreceiver/internal/otlp_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal"

import (
Expand Down Expand Up @@ -155,7 +154,9 @@ func (t *transaction) Commit() error {

if metricsL.Len() > 0 {
metrics := t.metricSliceToMetrics(metricsL)
t.sink.ConsumeMetrics(ctx, *metrics)
if err = t.sink.ConsumeMetrics(ctx, *metrics); err != nil {
return err
}
}

t.obsrecv.EndMetricsOp(ctx, dataformat, numPoints, nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package prometheusreceiver

import (
Expand Down Expand Up @@ -197,22 +196,22 @@ func TestHonorTimeStampsWithFalse(t *testing.T) {
func setMetricsTimestamp() {
onlyOnce.Do(func() {
honorTimestampsPage1 = fmt.Sprintf(honorTimestampsPage1,
ts1, //timestamp for gauge
ts2, ts3, //timestamp for counter
ts4, ts4, ts4, ts4, ts4, ts4, //timestamp for histogram
ts5, ts5, ts5, ts5, ts5, //timestamp for summary
ts1, // timestamp for gauge
ts2, ts3, // timestamp for counter
ts4, ts4, ts4, ts4, ts4, ts4, // timestamp for histogram
ts5, ts5, ts5, ts5, ts5, // timestamp for summary
)
honorTimestampsPage2 = fmt.Sprintf(honorTimestampsPage2,
ts6, //timestamp for gauge
ts7, ts8, //timestamp for counter
ts9, ts9, ts9, ts9, ts9, ts9, //timestamp for histogram
ts10, ts10, ts10, ts10, ts10, //timestamp for summary
ts6, // timestamp for gauge
ts7, ts8, // timestamp for counter
ts9, ts9, ts9, ts9, ts9, ts9, // timestamp for histogram
ts10, ts10, ts10, ts10, ts10, // timestamp for summary
)
honorTimestampsPage3 = fmt.Sprintf(honorTimestampsPage3,
ts11, //timestamp for gauge
ts12, ts13, //timestamp for counter
ts14, ts14, ts14, ts14, ts14, ts14, //timestamp for histogram
ts15, ts15, ts15, ts15, ts15, //timestamp for summary
ts11, // timestamp for gauge
ts12, ts13, // timestamp for counter
ts14, ts14, ts14, ts14, ts14, ts14, // timestamp for histogram
ts15, ts15, ts15, ts15, ts15, // timestamp for summary
)
})
}
Expand Down
13 changes: 6 additions & 7 deletions receiver/prometheusreceiver/metrics_receiver_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package prometheusreceiver

import (
Expand Down Expand Up @@ -77,7 +76,7 @@ test_gauge0{label1="value1",label2="value2"} 10
`

func verifyLabelLimitTarget1(t *testing.T, td *testData, rms []*pmetric.ResourceMetrics) {
//each sample in the scraped metrics is within the configured label_limit, scrape should be successful
// each sample in the scraped metrics is within the configured label_limit, scrape should be successful
verifyNumValidScrapeResults(t, td, rms)
require.Greater(t, len(rms), 0, "At least one resource metric should be present")

Expand Down Expand Up @@ -108,7 +107,7 @@ test_gauge0{label1="value1",label2="value2",label3="value3"} 10
`

func verifyFailedScrape(t *testing.T, _ *testData, rms []*pmetric.ResourceMetrics) {
//Scrape should be unsuccessful since limit is exceeded in target2
// Scrape should be unsuccessful since limit is exceeded in target2
for _, rm := range rms {
metrics := getMetrics(rm)
assertUp(t, 0, metrics)
Expand Down Expand Up @@ -301,7 +300,7 @@ func TestLabelValueLimitConfig(t *testing.T) {
})
}

//for all metric types, testLabel has empty value
// for all metric types, testLabel has empty value
const emptyLabelValuesTarget1 = `
# HELP test_gauge0 This is my gauge
# TYPE test_gauge0 gauge
Expand Down Expand Up @@ -489,15 +488,15 @@ func verifyHonorLabelsFalse(t *testing.T, td *testData, rms []*pmetric.ResourceM
numberPointComparator: []numberPointComparator{
compareTimestamp(ts1),
compareDoubleValue(1),
//job and instance labels must be prefixed with "exported_"
// job and instance labels must be prefixed with "exported_"
compareAttributes(map[string]string{"exported_job": "honor_labels_test", "exported_instance": "hostname:8080", "testLabel": "value1"}),
},
},
}),
})
}

//for all scalar metric types there are no labels
// for all scalar metric types there are no labels
const emptyLabelsTarget1 = `
# HELP test_gauge0 This is my gauge
# TYPE test_gauge0 gauge
Expand Down Expand Up @@ -576,7 +575,7 @@ func TestHonorLabelsFalseConfig(t *testing.T) {
func verifyHonorLabelsTrue(t *testing.T, td *testData, rms []*pmetric.ResourceMetrics) {
require.Greater(t, len(rms), 0, "At least one resource metric should be present")

//job and instance label values should be honored from honorLabelsTarget
// job and instance label values should be honored from honorLabelsTarget
expectedAttributes := td.attributes
expectedAttributes.Update("service.name", pcommon.NewValueString("honor_labels_test"))
expectedAttributes.Update("service.instance.id", pcommon.NewValueString("hostname:8080"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package prometheusreceiver

import (
Expand Down Expand Up @@ -142,7 +141,7 @@ func verifyStaleNaNPage1SuccessfulScrape(t *testing.T, td *testData, resourceMet
histogramPointComparator: []histogramPointComparator{
// TODO: #6360 Prometheus Receiver Issue- start_timestamp are incorrect
// for Summary and Histogram metrics after a failed scrape
//compareHistogramStartTimestamp(*startTimestamp),
// compareHistogramStartTimestamp(*startTimestamp),
compareHistogramTimestamp(ts1),
compareHistogram(2500, 5000, []uint64{1000, 500, 500, 500}),
},
Expand All @@ -155,7 +154,7 @@ func verifyStaleNaNPage1SuccessfulScrape(t *testing.T, td *testData, resourceMet
summaryPointComparator: []summaryPointComparator{
// TODO: #6360 Prometheus Receiver Issue- start_timestamp are incorrect
// for Summary and Histogram metrics after a failed scrape
//compareSummaryStartTimestamp(*startTimestamp),
// compareSummaryStartTimestamp(*startTimestamp),
compareSummaryTimestamp(ts1),
compareSummary(1000, 5000, [][]float64{{0.01, 1}, {0.9, 5}, {0.99, 8}}),
},
Expand Down Expand Up @@ -237,7 +236,7 @@ var normalNaNsPage1 = `
go_threads NaN
# HELP redis_connected_clients Redis connected clients
redis_connected_clients{name="rough-snowflake-web",port="6380"} NaN
redis_connected_clients{name="rough-snowflake-web",port="6380"} NaN
# HELP rpc_duration_seconds A summary of the RPC duration in seconds.
# TYPE rpc_duration_seconds summary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:gocritic
package prometheusreceiver

import (
Expand All @@ -31,7 +30,6 @@ import (

const testDir = "./testdata/openmetrics/"

// nolint:unused
var skippedTests = map[string]struct{}{
"bad_clashing_names_0": {}, "bad_clashing_names_1": {}, "bad_clashing_names_2": {},
"bad_counter_values_0": {}, "bad_counter_values_1": {}, "bad_counter_values_2": {},
Expand Down Expand Up @@ -84,7 +82,6 @@ func TestOpenMetricsPositive(t *testing.T) {
testComponent(t, targets, false, "")
}

// nolint:unused
func verifyNegativeTarget(t *testing.T, td *testData, mds []*pmetric.ResourceMetrics) {
// failing negative tests are skipped since prometheus scrape package is currently not fully
// compatible with OpenMetrics tests and successfully scrapes some invalid metrics
Expand All @@ -100,7 +97,7 @@ func verifyNegativeTarget(t *testing.T, td *testData, mds []*pmetric.ResourceMet

// Test open metrics negative test cases
func TestOpenMetricsNegative(t *testing.T) {
t.Skip("Flaky test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/9119")
skip(t, "Flaky test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/9119")

targetsMap := getOpenMetricsTestData(true)
targets := make([]*testData, 0)
Expand All @@ -119,20 +116,20 @@ func TestOpenMetricsNegative(t *testing.T) {
testComponent(t, targets, false, "")
}

//reads test data from testdata/openmetrics directory
// reads test data from testdata/openmetrics directory
func getOpenMetricsTestData(negativeTestsOnly bool) map[string]string {
testDir, err := os.Open(testDir)
if err != nil {
log.Fatalf("failed opening openmetrics test directory")
}
defer testDir.Close()

//read all test file names in testdata/openmetrics
// read all test file names in testdata/openmetrics
testList, _ := testDir.Readdirnames(0)

targetsData := make(map[string]string)
for _, testName := range testList {
//ignore hidden files
// ignore hidden files
if strings.HasPrefix(testName, ".") {
continue
}
Expand Down

0 comments on commit 877066b

Please sign in to comment.