Skip to content

Commit 445277b

Browse files
authored
Merge pull request #2506 from Shopify/sveiss/port-patches-to-0.56
Port Shopify patches to v0.56
2 parents 124cb2c + 27fd64a commit 445277b

File tree

27 files changed

+365
-917
lines changed

27 files changed

+365
-917
lines changed

.github/dependabot.yml

+15-663
Large diffs are not rendered by default.

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,23 @@ gendependabot:
158158
@echo " - package-ecosystem: \"github-actions\"" >> ${DEPENDABOT_PATH}
159159
@echo " directory: \"/\"" >> ${DEPENDABOT_PATH}
160160
@echo " schedule:" >> ${DEPENDABOT_PATH}
161-
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}
161+
@echo " interval: \"monthly\"" >> ${DEPENDABOT_PATH}
162162
@echo "Add entry for \"/\" docker"
163163
@echo " - package-ecosystem: \"docker\"" >> ${DEPENDABOT_PATH}
164164
@echo " directory: \"/\"" >> ${DEPENDABOT_PATH}
165165
@echo " schedule:" >> ${DEPENDABOT_PATH}
166-
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}
166+
@echo " interval: \"monthly\"" >> ${DEPENDABOT_PATH}
167167
@echo "Add entry for \"/\" gomod"
168168
@echo " - package-ecosystem: \"gomod\"" >> ${DEPENDABOT_PATH}
169169
@echo " directory: \"/\"" >> ${DEPENDABOT_PATH}
170170
@echo " schedule:" >> ${DEPENDABOT_PATH}
171-
@echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}
171+
@echo " interval: \"monthly\"" >> ${DEPENDABOT_PATH}
172172
@set -e; for dir in $(NONROOT_MODS); do \
173173
echo "Add entry for \"$${dir:1}\""; \
174174
echo " - package-ecosystem: \"gomod\"" >> ${DEPENDABOT_PATH}; \
175175
echo " directory: \"$${dir:1}\"" >> ${DEPENDABOT_PATH}; \
176176
echo " schedule:" >> ${DEPENDABOT_PATH}; \
177-
echo " interval: \"weekly\"" >> ${DEPENDABOT_PATH}; \
177+
echo " interval: \"monthly\"" >> ${DEPENDABOT_PATH}; \
178178
done
179179

180180
# Define a delegation target for each module

cmd/configschema/go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -948,3 +948,5 @@ exclude github.com/StackExchange/wmi v1.2.0
948948

949949
// see https://github.com/distribution/distribution/issues/3590
950950
exclude github.com/docker/distribution v2.8.0+incompatible
951+
952+
replace github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.12.2-0.20220318110013-3bc8f2c651ff

cmd/configschema/go.sum

+2-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/prometheusexporter/collector.go

+25
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,36 @@ func (c *collector) convertDoubleHistogram(metric pmetric.Metric, resourceAttrs
209209
points[bucket] = cumCount
210210
}
211211

212+
arrLen := ip.Exemplars().Len()
213+
exemplars := make([]prometheus.Exemplar, arrLen)
214+
for i := 0; i < arrLen; i++ {
215+
e := ip.Exemplars().At(i)
216+
217+
labels := make(prometheus.Labels, e.FilteredAttributes().Len())
218+
e.FilteredAttributes().Range(func(k string, v pcommon.Value) bool {
219+
labels[k] = v.AsString()
220+
return true
221+
})
222+
223+
exemplars[i] = prometheus.Exemplar{
224+
Value: e.DoubleVal(),
225+
Labels: labels,
226+
Timestamp: e.Timestamp().AsTime(),
227+
}
228+
}
229+
212230
m, err := prometheus.NewConstHistogram(desc, ip.Count(), ip.Sum(), points, attributes...)
213231
if err != nil {
214232
return nil, err
215233
}
216234

235+
if arrLen > 0 {
236+
m, err = prometheus.NewMetricWithExemplars(m, exemplars...)
237+
if err != nil {
238+
return nil, err
239+
}
240+
}
241+
217242
if c.sendTimestamps {
218243
return prometheus.NewMetricWithTimestamp(ip.Timestamp().AsTime(), m), nil
219244
}

exporter/prometheusexporter/collector_test.go

+78
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,84 @@ func TestConvertInvalidMetric(t *testing.T) {
9696
}
9797
}
9898

99+
func TestConvertDoubleHistogramExemplar(t *testing.T) {
100+
// initialize empty histogram
101+
metric := pmetric.NewMetric()
102+
metric.SetDataType(pmetric.MetricDataTypeHistogram)
103+
metric.SetName("test_metric")
104+
metric.SetDescription("this is test metric")
105+
metric.SetUnit("T")
106+
107+
// initialize empty datapoint
108+
hd := metric.Histogram().DataPoints().AppendEmpty()
109+
110+
bounds := []float64{5, 25, 90}
111+
hd.SetMExplicitBounds(bounds)
112+
bc := []uint64{2, 35, 70}
113+
hd.SetMBucketCounts(bc)
114+
115+
exemplarTs, _ := time.Parse("unix", "Mon Jan _2 15:04:05 MST 2006")
116+
exemplars := []prometheus.Exemplar{
117+
{
118+
Timestamp: exemplarTs,
119+
Value: 3,
120+
Labels: prometheus.Labels{"test_label_0": "label_value_0"},
121+
},
122+
{
123+
Timestamp: exemplarTs,
124+
Value: 50,
125+
Labels: prometheus.Labels{"test_label_1": "label_value_1"},
126+
},
127+
{
128+
Timestamp: exemplarTs,
129+
Value: 78,
130+
Labels: prometheus.Labels{"test_label_2": "label_value_2"},
131+
},
132+
}
133+
134+
// add each exemplar value to the metric
135+
for _, e := range exemplars {
136+
pde := hd.Exemplars().AppendEmpty()
137+
pde.SetDoubleVal(e.Value)
138+
for k, v := range e.Labels {
139+
pde.FilteredAttributes().InsertString(k, v)
140+
}
141+
pde.SetTimestamp(pcommon.NewTimestampFromTime(e.Timestamp))
142+
}
143+
144+
c := collector{
145+
accumulator: &mockAccumulator{
146+
[]pmetric.Metric{metric},
147+
pcommon.NewMap(),
148+
},
149+
logger: zap.NewNop(),
150+
}
151+
152+
pbMetric, _ := c.convertDoubleHistogram(metric, pcommon.NewMap())
153+
m := io_prometheus_client.Metric{}
154+
require.NoError(t, pbMetric.Write(&m))
155+
156+
buckets := m.GetHistogram().GetBucket()
157+
158+
require.Equal(t, 3, len(buckets))
159+
160+
require.Equal(t, 3.0, buckets[0].GetExemplar().GetValue())
161+
require.Equal(t, int32(128654848), buckets[0].GetExemplar().GetTimestamp().GetNanos())
162+
require.Equal(t, 1, len(buckets[0].GetExemplar().GetLabel()))
163+
require.Equal(t, "test_label_0", buckets[0].GetExemplar().GetLabel()[0].GetName())
164+
require.Equal(t, "label_value_0", buckets[0].GetExemplar().GetLabel()[0].GetValue())
165+
166+
require.Equal(t, 0.0, buckets[1].GetExemplar().GetValue())
167+
require.Equal(t, int32(0), buckets[1].GetExemplar().GetTimestamp().GetNanos())
168+
require.Equal(t, 0, len(buckets[1].GetExemplar().GetLabel()))
169+
170+
require.Equal(t, 78.0, buckets[2].GetExemplar().GetValue())
171+
require.Equal(t, int32(128654848), buckets[2].GetExemplar().GetTimestamp().GetNanos())
172+
require.Equal(t, 1, len(buckets[2].GetExemplar().GetLabel()))
173+
require.Equal(t, "test_label_2", buckets[2].GetExemplar().GetLabel()[0].GetName())
174+
require.Equal(t, "label_value_2", buckets[2].GetExemplar().GetLabel()[0].GetValue())
175+
}
176+
99177
// errorCheckCore keeps track of logged errors
100178
type errorCheckCore struct {
101179
errorMessages []string

0 commit comments

Comments
 (0)