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 google.golang.org/grpc from 1.45.0 to 1.46.2 in /extension/oauth2clientauthextension #657

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
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