Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump go.opentelemetry.io/collector/model from 0.47.0 to 0.50.0 in /exporter/observiqexporter #312

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
352 changes: 180 additions & 172 deletions .github/dependabot.yml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,23 @@ gendependabot:
@echo " - package-ecosystem: \"github-actions\"" >> ${DEPENDABOT_PATH}
@echo " directory: \"/\"" >> ${DEPENDABOT_PATH}
@echo " schedule:" >> ${DEPENDABOT_PATH}
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}
@echo " interval: \"monthly\"" >> ${DEPENDABOT_PATH}
@echo "Add entry for \"/\" docker"
@echo " - package-ecosystem: \"docker\"" >> ${DEPENDABOT_PATH}
@echo " directory: \"/\"" >> ${DEPENDABOT_PATH}
@echo " schedule:" >> ${DEPENDABOT_PATH}
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}
@echo " interval: \"monthly\"" >> ${DEPENDABOT_PATH}
@echo "Add entry for \"/\" gomod"
@echo " - package-ecosystem: \"gomod\"" >> ${DEPENDABOT_PATH}
@echo " directory: \"/\"" >> ${DEPENDABOT_PATH}
@echo " schedule:" >> ${DEPENDABOT_PATH}
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}
@echo " interval: \"monthly\"" >> ${DEPENDABOT_PATH}
@set -e; for dir in $(ALL_MODULES); do \
echo "Add entry for \"$${dir:1}\""; \
echo " - package-ecosystem: \"gomod\"" >> ${DEPENDABOT_PATH}; \
echo " directory: \"$${dir:1}\"" >> ${DEPENDABOT_PATH}; \
echo " schedule:" >> ${DEPENDABOT_PATH}; \
echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}; \
echo " interval: \"monthly\"" >> ${DEPENDABOT_PATH}; \
done

GOMODULES = $(ALL_MODULES) $(PWD)
Expand Down
12 changes: 10 additions & 2 deletions exporter/observiqexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.17

require (
github.com/google/uuid v1.3.0
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.7.1
go.opentelemetry.io/collector v0.47.0
go.opentelemetry.io/collector/model v0.47.0
go.opentelemetry.io/collector/model v0.50.0
go.uber.org/multierr v1.8.0
go.uber.org/zap v1.21.0
)
Expand All @@ -15,6 +15,7 @@ require (
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/knadh/koanf v1.4.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
Expand All @@ -23,10 +24,17 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/collector/pdata v0.50.0 // indirect
go.opentelemetry.io/otel v1.4.1 // indirect
go.opentelemetry.io/otel/metric v0.27.0 // indirect
go.opentelemetry.io/otel/trace v1.4.1 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa // indirect
google.golang.org/grpc v1.46.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
449 changes: 445 additions & 4 deletions exporter/observiqexporter/go.sum

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions exporter/prometheusexporter/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (c *collector) convertDoubleHistogram(metric pdata.Metric) (prometheus.Metr

indicesMap := make(map[float64]int)
buckets := make([]float64, 0, len(ip.BucketCounts()))

for index, bucket := range ip.ExplicitBounds() {
if _, added := indicesMap[bucket]; !added {
indicesMap[bucket] = index
Expand All @@ -197,11 +198,36 @@ func (c *collector) convertDoubleHistogram(metric pdata.Metric) (prometheus.Metr
points[bucket] = cumCount
}

arrLen := ip.Exemplars().Len()
exemplars := make([]prometheus.Exemplar, arrLen)
for i := 0; i < arrLen; i++ {
e := ip.Exemplars().At(i)

labels := make(prometheus.Labels, e.FilteredAttributes().Len())
e.FilteredAttributes().Range(func(k string, v pdata.AttributeValue) bool {
labels[k] = v.AsString()
return true
})

exemplars[i] = prometheus.Exemplar{
Value: e.DoubleVal(),
Labels: labels,
Timestamp: e.Timestamp().AsTime(),
}
}

m, err := prometheus.NewConstHistogram(desc, ip.Count(), ip.Sum(), points, attributes...)
if err != nil {
return nil, err
}

if arrLen > 0 {
m, err = prometheus.NewMetricWithExemplars(m, exemplars...)
if err != nil {
return nil, err
}
}

if c.sendTimestamps {
return prometheus.NewMetricWithTimestamp(ip.Timestamp().AsTime(), m), nil
}
Expand Down
77 changes: 77 additions & 0 deletions exporter/prometheusexporter/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,83 @@ func TestConvertInvalidMetric(t *testing.T) {
}
}

func TestConvertDoubleHistogramExemplar(t *testing.T) {
// initialize empty histogram
metric := pdata.NewMetric()
metric.SetDataType(pdata.MetricDataTypeHistogram)
metric.SetName("test_metric")
metric.SetDescription("this is test metric")
metric.SetUnit("T")

// initialize empty datapoint
hd := metric.Histogram().DataPoints().AppendEmpty()

bounds := []float64{5, 25, 90}
hd.SetExplicitBounds(bounds)
bc := []uint64{2, 35, 70}
hd.SetBucketCounts(bc)

exemplarTs, _ := time.Parse("unix", "Mon Jan _2 15:04:05 MST 2006")
exemplars := []prometheus.Exemplar{
{
Timestamp: exemplarTs,
Value: 3,
Labels: prometheus.Labels{"test_label_0": "label_value_0"},
},
{
Timestamp: exemplarTs,
Value: 50,
Labels: prometheus.Labels{"test_label_1": "label_value_1"},
},
{
Timestamp: exemplarTs,
Value: 78,
Labels: prometheus.Labels{"test_label_2": "label_value_2"},
},
}

// add each exemplar value to the metric
for _, e := range exemplars {
pde := hd.Exemplars().AppendEmpty()
pde.SetDoubleVal(e.Value)
for k, v := range e.Labels {
pde.FilteredAttributes().InsertString(k, v)
}
pde.SetTimestamp(pdata.NewTimestampFromTime(e.Timestamp))
}

c := collector{
accumulator: &mockAccumulator{
[]pdata.Metric{metric},
},
logger: zap.NewNop(),
}

pbMetric, _ := c.convertDoubleHistogram(metric)
m := io_prometheus_client.Metric{}
pbMetric.Write(&m)

buckets := m.GetHistogram().GetBucket()

require.Equal(t, 3, len(buckets))

require.Equal(t, 3.0, buckets[0].GetExemplar().GetValue())
require.Equal(t, int32(128654848), buckets[0].GetExemplar().GetTimestamp().GetNanos())
require.Equal(t, 1, len(buckets[0].GetExemplar().GetLabel()))
require.Equal(t, "test_label_0", buckets[0].GetExemplar().GetLabel()[0].GetName())
require.Equal(t, "label_value_0", buckets[0].GetExemplar().GetLabel()[0].GetValue())

require.Equal(t, 0.0, buckets[1].GetExemplar().GetValue())
require.Equal(t, int32(0), buckets[1].GetExemplar().GetTimestamp().GetNanos())
require.Equal(t, 0, len(buckets[1].GetExemplar().GetLabel()))

require.Equal(t, 78.0, buckets[2].GetExemplar().GetValue())
require.Equal(t, int32(128654848), buckets[2].GetExemplar().GetTimestamp().GetNanos())
require.Equal(t, 1, len(buckets[2].GetExemplar().GetLabel()))
require.Equal(t, "test_label_2", buckets[2].GetExemplar().GetLabel()[0].GetName())
require.Equal(t, "label_value_2", buckets[2].GetExemplar().GetLabel()[0].GetValue())
}

// errorCheckCore keeps track of logged errors
type errorCheckCore struct {
errorMessages []string
Expand Down
3 changes: 3 additions & 0 deletions exporter/prometheusexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type Config struct {
// ResourceToTelemetrySettings defines configuration for converting resource attributes to metric labels.
ResourceToTelemetrySettings resourcetotelemetry.Settings `mapstructure:"resource_to_telemetry_conversion"`

// EnableOpenMetrics enables the use of the OpenMetrics encoding option for the prometheus exporter.
EnableOpenMetrics bool `mapstructure:"enable_open_metrics"`

// skipSanitizeLabel if enabled, labels that start with _ are not sanitized
skipSanitizeLabel bool
}
Expand Down
1 change: 1 addition & 0 deletions exporter/prometheusexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func createDefaultConfig() config.Exporter {
ConstLabels: map[string]string{},
SendTimestamps: false,
MetricExpiration: time.Minute * 5,
EnableOpenMetrics: false,
skipSanitizeLabel: featuregate.IsEnabled(dropSanitizationGate.ID),
}
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/prometheusexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.47.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.47.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.47.0
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_golang v1.12.2-0.20220318110013-3bc8f2c651ff
github.com/prometheus/client_model v0.2.0
github.com/prometheus/prometheus v1.8.2-0.20220117154355-4855a0c067e2
github.com/stretchr/testify v1.7.0
Expand Down
Loading