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

add helper.go and tests #5

Closed
wants to merge 70 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
06753d6
set up project structure
huyan0 Jul 30, 2020
287a4e5
placeholder text for README
huyan0 Jul 30, 2020
c7e2a42
finish Test_validateMetrics
huyan0 Jul 30, 2020
0f6033f
finish Test_validateMetrics
huyan0 Jul 30, 2020
0686608
finish Test_validateMetrics
huyan0 Jul 30, 2020
a896535
remove extra import
huyan0 Jul 30, 2020
6335403
fix format error so that make runs
huyan0 Jul 30, 2020
f76b22a
update unit tests
huyan0 Jul 30, 2020
91dddb9
Testbed for the config and factory constructions:
Jul 30, 2020
66224aa
Testbed for the config and factory constructions, possible README.md …
Jul 30, 2020
2e4b1e1
Testbed oop
Jul 30, 2020
01441e7
add metrictest util code
huyan0 Jul 31, 2020
a9eaaec
tempeorary code
huyan0 Jul 31, 2020
7cf119b
finish testutil and Test_addSample
huyan0 Jul 31, 2020
5625330
add more unit tests
huyan0 Aug 1, 2020
cbd7f6e
add unit tests
huyan0 Aug 2, 2020
a4d7eeb
use assert.Exactly
huyan0 Aug 2, 2020
ae1758c
finish Test_handleHistogramMetric
huyan0 Aug 2, 2020
93df3e9
fix Test_handleScalarMetric to include metric name in label set
huyan0 Aug 2, 2020
346fce0
finish Test_handleSummaryMetric
huyan0 Aug 2, 2020
d215b33
add Test_shutdown
huyan0 Aug 2, 2020
b001c18
add unit test for functions
huyan0 Aug 2, 2020
64aad65
add unit tests for cortex.go
huyan0 Aug 3, 2020
b55576e
associated methods with cortexExporter
huyan0 Aug 3, 2020
ad4f1b1
some more config and factory stuff:
Aug 3, 2020
5806a51
M branch 'unit-tests' of https://github.com/open-o11y/opentelemetry-c…
Aug 3, 2020
d670578
config and some factory, export skeleton
Aug 3, 2020
d125a28
config and some factory, export skeleton
Aug 3, 2020
34b40fe
add nil test cases for cortex.go
huyan0 Aug 3, 2020
32a9db9
implement and test validateMetrics and addSample
huyan0 Aug 3, 2020
c466bd9
implement and test timeSeriesSignature
huyan0 Aug 3, 2020
c7a0dc1
implement and test createLabelSet
huyan0 Aug 3, 2020
b978fd4
finish createMetricsExporter method
huyan0 Aug 3, 2020
3992ea7
work
Aug 3, 2020
01ad87a
factory
Aug 3, 2020
da4dbcc
no more const labels for config
Aug 3, 2020
0312ced
implement and test handleScalarMetric
huyan0 Aug 3, 2020
d868fd9
implement and test handleScalarMetric
huyan0 Aug 3, 2020
cadd3bf
Update factory.go
huyan0 Aug 3, 2020
184e16a
implement and test handleHistogramMetric
huyan0 Aug 3, 2020
d0d700b
Merge branch 'unit-tests' of github.com:open-o11y/opentelemetry-colle…
huyan0 Aug 3, 2020
a133149
implement and test handleHistogramMetric
huyan0 Aug 3, 2020
222ea87
implement and test handleSummaryMetric
huyan0 Aug 3, 2020
c7ce3c6
implement shutdown
huyan0 Aug 3, 2020
a4f09ab
opt headers for config
Aug 3, 2020
100d482
Mergeae branch 'unit-tests' of https://github.com/open-o11y/opentelem…
Aug 3, 2020
ca1295e
undupped create Metrics Exporter
Aug 3, 2020
4bc9a4f
test shutdown
huyan0 Aug 3, 2020
db605f2
Merge branch 'unit-tests' of github.com:open-o11y/opentelemetry-colle…
huyan0 Aug 3, 2020
4a29b98
yes
Aug 3, 2020
c4d8d47
okay, worksMerge branch 'unit-tests' of https://github.com/open-o11y/…
Aug 3, 2020
6073ce3
remove usage of getSample in cortex.go
huyan0 Aug 3, 2020
3c12ab7
Merge branch 'unit-tests' of github.com:open-o11y/opentelemetry-colle…
huyan0 Aug 3, 2020
37db943
implement and test newMetricsExporter
huyan0 Aug 4, 2020
e9ac299
Test_pushMetrics not working
huyan0 Aug 4, 2020
53fbe2b
add comments to and format cortex.go
huyan0 Aug 4, 2020
96807eb
make cortex_test readable
huyan0 Aug 4, 2020
4182996
modify things in factory.go
huyan0 Aug 4, 2020
8ac6b25
update TODOs in cortex_test
huyan0 Aug 4, 2020
9a69f18
updated go.mod
huyan0 Aug 4, 2020
cf8fcaf
add headers field to exporter struct
huyan0 Aug 4, 2020
f223b37
fix config_test
huyan0 Aug 4, 2020
3371a59
add todos
huyan0 Aug 4, 2020
2cb879a
create helper.go and helper_test.go
huyan0 Aug 4, 2020
071b82d
add cortex.go and helper.go with tests
huyan0 Aug 4, 2020
fda582b
fix cortex_test.go
huyan0 Aug 4, 2020
05bcd9d
add comments to tests and address style issues
huyan0 Aug 5, 2020
4042156
add DO NOT REVIEW message in certain files
huyan0 Aug 5, 2020
72289fd
new branch with only helper.go and tests
huyan0 Aug 5, 2020
a0e505b
update comments
huyan0 Aug 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
yes
Daniel Bang committed Aug 3, 2020
commit 4a29b98b024013655047a23dcb57974ca499ae2a
2 changes: 1 addition & 1 deletion exporter/cortexexporter/config.go
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ type Config struct {
Namespace string `mapstructure:"namespace"`

// Optional headers configuration for authorization and security/extra metadata
Headers []string `mapstructure:"optional_headers"`
Headers map[string]string `mapstructure:"optional_headers"`

HTTPClientSettings confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.

2 changes: 1 addition & 1 deletion exporter/cortexexporter/config_test.go
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ func TestLoadConfig(t *testing.T) {
},
Namespace: "test-space",

Headers: []string{"example_header1", "example_header2"},
Headers: map[string]string{"example_header1": "example_header_value1"},

HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "localhost:8888",
62 changes: 34 additions & 28 deletions exporter/cortexexporter/cortex_test.go
Original file line number Diff line number Diff line change
@@ -16,14 +16,15 @@ package cortexexporter

import (
"context"
"strconv"
"sync"
"testing"

"github.com/prometheus/prometheus/prompb"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer/pdatautil"
common "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/common/v1"
"go.opentelemetry.io/collector/internal/data/testdata"
"strconv"
"sync"
"testing"

"github.com/stretchr/testify/assert"

@@ -126,7 +127,7 @@ func Test_addSample(t *testing.T) {
}
t.Run("nil_case", func(t *testing.T) {
tsMap := map[string]*prompb.TimeSeries{}
addSample(tsMap, nil,nil,0)
addSample(tsMap, nil, nil, 0)
assert.Exactly(t, tsMap, map[string]*prompb.TimeSeries{})
})
// run tests
@@ -160,7 +161,7 @@ func Test_timeSeriesSignature(t *testing.T) {
},
{
"unordered_signature",
getPromLabels(label22, value22,label21, value21, ),
getPromLabels(label22, value22, label21, value21),
otlp.MetricDescriptor_HISTOGRAM,
typeHistogram + "-" + label21 + "-" + value21 + "-" + label22 + "-" + value22,
},
@@ -225,14 +226,14 @@ func Test_createLabelSet(t *testing.T) {

func Test_handleScalarMetric(t *testing.T) {
sameTs := map[string]*prompb.TimeSeries{
typeMonotonicInt64 + "-name-same_ts_int_points_total" + "-" + label11 + "-" + value11 + "-" + label12 + "-" + value12: getTimeSeries(getPromLabels(label11, value11, label12, value12, "name", "same_ts_int_points_total"),
typeMonotonicInt64 + "-name-same_ts_int_points_total" + "-" + label11 + "-" + value11 + "-" + label12 + "-" + value12: getTimeSeries(getPromLabels(label11, value11, label12, value12, "name", "same_ts_int_points_total"),
getSample(float64(intVal1), time1),
getSample(float64(intVal2), time1)),
}
differentTs := map[string]*prompb.TimeSeries{
typeMonotonicInt64 + "-name-different_ts_int_points_total" + "-" + label11 + "-" + value11 + "-" + label12 + "-" + value12: getTimeSeries(getPromLabels(label11, value11, label12, value12, "name", "different_ts_int_points_total"),
typeMonotonicInt64 + "-name-different_ts_int_points_total" + "-" + label11 + "-" + value11 + "-" + label12 + "-" + value12: getTimeSeries(getPromLabels(label11, value11, label12, value12, "name", "different_ts_int_points_total"),
getSample(float64(intVal1), time1)),
typeMonotonicInt64 + "-name-different_ts_int_points_total"+ "-" + label21 + "-" + value21 + "-" + label22 + "-" + value22: getTimeSeries(getPromLabels(label21, value21, label22, value22, "name", "different_ts_int_points_total"),
typeMonotonicInt64 + "-name-different_ts_int_points_total" + "-" + label21 + "-" + value21 + "-" + label22 + "-" + value22: getTimeSeries(getPromLabels(label21, value21, label22, value22, "name", "different_ts_int_points_total"),
getSample(float64(intVal1), time2)),
}
tests := []struct {
@@ -294,11 +295,11 @@ func Test_handleScalarMetric(t *testing.T) {
assert.Error(t, ok)
return
}
assert.Exactly(t,len(tt.want), len(tsMap))
for k,v := range tsMap {
require.NotNil(t,tt.want[k])
assert.ElementsMatch(t, tt.want[k].Labels,v.Labels)
assert.ElementsMatch(t, tt.want[k].Samples,v.Samples)
assert.Exactly(t, len(tt.want), len(tsMap))
for k, v := range tsMap {
require.NotNil(t, tt.want[k])
assert.ElementsMatch(t, tt.want[k].Labels, v.Labels)
assert.ElementsMatch(t, tt.want[k].Samples, v.Samples)
}
})
}
@@ -396,11 +397,11 @@ func Test_handleHistogramMetric(t *testing.T) {
assert.Error(t, ok)
return
}
assert.Exactly(t,len(tt.want), len(tsMap))
for k,v := range tsMap {
require.NotNil(t,tt.want[k],k)
assert.ElementsMatch(t, tt.want[k].Labels,v.Labels)
assert.ElementsMatch(t, tt.want[k].Samples,v.Samples)
assert.Exactly(t, len(tt.want), len(tsMap))
for k, v := range tsMap {
require.NotNil(t, tt.want[k], k)
assert.ElementsMatch(t, tt.want[k].Labels, v.Labels)
assert.ElementsMatch(t, tt.want[k].Samples, v.Samples)
}
})
}
@@ -415,9 +416,9 @@ func Test_handleSummaryMetric(t *testing.T) {
sum: typeSummary + "-name-valid_single_int_point_sum-" + label11 + "-" + value11 + "-" + label12 + "-" + value12,
count: typeSummary + "-name-valid_single_int_point_count-" + label11 + "-" + value11 + "-" + label12 + "-" + value12,
q1: typeSummary + "-name-valid_single_int_point-" + "quantile-" + strconv.FormatFloat(floatVal1, 'f', -1, 64) +
"-"+ label11 + "-" + value11 + "-" + label12 + "-" + value12,
"-" + label11 + "-" + value11 + "-" + label12 + "-" + value12,
q2: typeSummary + "-name-valid_single_int_point-" + "quantile-" + strconv.FormatFloat(floatVal2, 'f', -1, 64) +
"-" +label11 + "-" + value11 + "-" + label12 + "-" + value12,
"-" + label11 + "-" + value11 + "-" + label12 + "-" + value12,
}
lbls := map[string][]prompb.Label{
sum: append(promLbs1, getPromLabels("name", "valid_single_int_point_sum")...),
@@ -434,7 +435,7 @@ func Test_handleSummaryMetric(t *testing.T) {
Count: uint64(intVal2),
Sum: floatVal2,
PercentileValues: []*otlp.SummaryDataPoint_ValueAtPercentile{
{ floatVal1,
{floatVal1,
floatVal1,
},
{floatVal2,
@@ -487,11 +488,11 @@ func Test_handleSummaryMetric(t *testing.T) {
assert.Error(t, ok)
return
}
assert.Exactly(t,len(tt.want), len(tsMap))
for k,v := range tsMap {
require.NotNil(t,tt.want[k],k)
assert.ElementsMatch(t, tt.want[k].Labels,v.Labels)
assert.ElementsMatch(t, tt.want[k].Samples,v.Samples)
assert.Exactly(t, len(tt.want), len(tsMap))
for k, v := range tsMap {
require.NotNil(t, tt.want[k], k)
assert.ElementsMatch(t, tt.want[k].Labels, v.Labels)
assert.ElementsMatch(t, tt.want[k].Samples, v.Samples)
}
})
}
@@ -500,7 +501,7 @@ func Test_handleSummaryMetric(t *testing.T) {
// test after shutdown is called, incoming calls to pushMetrics return error.
func Test_shutdown(t *testing.T) {
ce := &cortexExporter{
wg:new(sync.WaitGroup),
wg: new(sync.WaitGroup),
closeChan: make(chan struct{}),
}
ce.shutdown(context.Background())
@@ -520,6 +521,11 @@ func Test_shutdown(t *testing.T) {
assert.Error(t, ok)
}
}

func Test_Export(t *testing.T) {
return
}

/*
func Test_newCortexExporter(t *testing.T) {
config := &Config{
@@ -635,4 +641,4 @@ func Test_pushMetrics(t *testing.T) {
})
}
}
*/
*/