Skip to content

Commit

Permalink
[chore] [receiver/k8scluster] Remove dead code (#24535)
Browse files Browse the repository at this point in the history
As a result of the effort to move metrics in the k8s cluster receiver to
use the pdata format instead of OpenCensus, some helper methods are now
unused. This change removes unused code.
  • Loading branch information
crobert-1 authored and SimunKaracic committed Jul 26, 2023
1 parent d52c6db commit 46e1e86
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 145 deletions.
89 changes: 0 additions & 89 deletions receiver/k8sclusterreceiver/internal/testutils/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,10 @@ package testutils // import "github.com/open-telemetry/opentelemetry-collector-c
import (
"testing"

metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pmetric"
)

func AssertResource(t *testing.T, actualResource *resourcepb.Resource,
expectedType string, expectedLabels map[string]string) {
require.Equal(t,
expectedType,
actualResource.Type,
"mismatching resource types",
)

require.Equal(t,
expectedLabels,
actualResource.Labels,
"mismatching resource labels",
)
}

func AssertMetricInt(t testing.TB, m pmetric.Metric, expectedMetric string, expectedType pmetric.MetricType, expectedValue any) {
dps := assertMetric(t, m, expectedMetric, expectedType)
require.EqualValues(t, expectedValue, dps.At(0).IntValue(), "mismatching metric values")
Expand Down Expand Up @@ -54,75 +37,3 @@ func assertMetric(t testing.TB, m pmetric.Metric, expectedMetric string, expecte
require.Equal(t, 1, dps.Len())
return dps
}

func AssertMetricsWithLabels(t *testing.T, actualMetric *metricspb.Metric,
expectedMetric string, expectedType metricspb.MetricDescriptor_Type,
expectedLabels map[string]string, expectedValue int64) {

require.Equal(t,
len(expectedLabels),
len(actualMetric.MetricDescriptor.LabelKeys),
"mismatching number of labels",
)

require.Equal(t,
expectedLabels,
getLabelsMap(actualMetric),
"mismatching labels",
)

AssertMetricsInt(t, actualMetric, expectedMetric, expectedType, expectedValue)
}

func AssertMetricsInt(t *testing.T, actualMetric *metricspb.Metric, expectedMetric string,
expectedType metricspb.MetricDescriptor_Type, expectedValue int64) {
assertMetricsBase(t, actualMetric, expectedMetric, expectedType)

require.Equal(t,
expectedValue,
actualMetric.Timeseries[0].Points[0].GetInt64Value(),
"mismatching metric values",
)
}

func AssertMetricsDouble(t *testing.T, actualMetric *metricspb.Metric, expectedMetric string,
expectedType metricspb.MetricDescriptor_Type, expectedValue float64) {
assertMetricsBase(t, actualMetric, expectedMetric, expectedType)

require.Equal(t,
expectedValue,
actualMetric.Timeseries[0].Points[0].GetDoubleValue(),
"mismatching metric values",
)
}

func assertMetricsBase(t *testing.T, actualMetric *metricspb.Metric, expectedMetric string,
expectedType metricspb.MetricDescriptor_Type) {

require.Equal(t,
expectedMetric,
actualMetric.MetricDescriptor.Name,
"mismatching metric names",
)

require.NotEmpty(t,
actualMetric.MetricDescriptor.Description,
"empty description on metric",
)

require.Equal(t,
expectedType,
actualMetric.MetricDescriptor.Type,
"mismatching metric types",
)
}

// getLabelsMap returns a map of labels.
func getLabelsMap(m *metricspb.Metric) map[string]string {
out := map[string]string{}
for i, k := range m.MetricDescriptor.LabelKeys {
out[k.Key] = m.Timeseries[0].LabelValues[i].Value
}

return out
}
28 changes: 0 additions & 28 deletions receiver/k8sclusterreceiver/internal/utils/timeseries.go

This file was deleted.

28 changes: 0 additions & 28 deletions receiver/k8sclusterreceiver/internal/utils/timeseries_test.go

This file was deleted.

0 comments on commit 46e1e86

Please sign in to comment.