From 8ac6b25f2ebf350f8df4ac4b25672b5fe057891e Mon Sep 17 00:00:00 2001 From: Yang Hu Date: Tue, 4 Aug 2020 09:27:59 -0500 Subject: [PATCH 1/3] update TODOs in cortex_test --- exporter/cortexexporter/cortex_test.go | 8 ++++---- exporter/cortexexporter/factory.go | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/exporter/cortexexporter/cortex_test.go b/exporter/cortexexporter/cortex_test.go index c20bebafb65..cc6cd1538f2 100644 --- a/exporter/cortexexporter/cortex_test.go +++ b/exporter/cortexexporter/cortex_test.go @@ -41,9 +41,7 @@ import ( // "github.com/stretchr/testify/require" ) -// TODO: make sure nil case is checked in every test -// TODO: add unordered labels test case for Test_timeSeriesSignature -// TODO: try to run Test_newCortexExporter and Test_PushMetrics after factory and config.go are in +// TODO: try to run Test_PushMetrics after export is in // TODO: add bucket and histogram test cases for Test_PushMetrics //return false if descriptor type is nil @@ -569,7 +567,8 @@ func Test_newCortexExporter(t *testing.T) { assert.NotNil(t, ce.closeChan) assert.NotNil(t, ce.wg) } -// Bug{@huyan0} success case pass but it should fail +// Bug{@huyan0} success case pass but it should fail; this is because the server gets no request because export() is +// empty. // test the correctness and the number of points func Test_pushMetrics(t *testing.T) { noTempBatch := pdatautil.MetricsFromInternalMetrics(testdata.GenerateMetricDataManyMetricsSameResource(10)) @@ -646,6 +645,7 @@ func Test_pushMetrics(t *testing.T) { assert.NoError(t, err) config := createDefaultConfig().(*Config) + assert.NotNil(t,config) config.HTTPClientSettings.Endpoint = serverURL.String() c, err := config.HTTPClientSettings.ToClient() assert.Nil(t,err) diff --git a/exporter/cortexexporter/factory.go b/exporter/cortexexporter/factory.go index 0132a493edc..5475a671a5a 100644 --- a/exporter/cortexexporter/factory.go +++ b/exporter/cortexexporter/factory.go @@ -105,6 +105,9 @@ func createDefaultConfig() configmodels.Exporter { TypeVal: typeStr, NameVal: typeStr, }, + Namespace: "", + Headers: map[string]string{}, + TimeoutSettings: exporterhelper.CreateDefaultTimeoutSettings(), RetrySettings: exporterhelper.CreateDefaultRetrySettings(), QueueSettings: qs, From 9a69f18049d98281e31dbaad601dea44560f048e Mon Sep 17 00:00:00 2001 From: Yang Hu Date: Tue, 4 Aug 2020 09:44:26 -0500 Subject: [PATCH 2/3] updated go.mod --- go.mod | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.mod b/go.mod index ac73febc0b7..3fd2ab16117 100644 --- a/go.mod +++ b/go.mod @@ -68,6 +68,4 @@ require ( google.golang.org/protobuf v1.25.0 gopkg.in/yaml.v2 v2.3.0 honnef.co/go/tools v0.0.1-2020.1.4 - github.com/golang/snappy v0.0.1 - github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e ) From cf8fcaf6135ead713fab88e73d110da8e171245d Mon Sep 17 00:00:00 2001 From: Yang Hu Date: Tue, 4 Aug 2020 10:55:02 -0500 Subject: [PATCH 3/3] add headers field to exporter struct --- exporter/cortexexporter/config.go | 1 - exporter/cortexexporter/cortex.go | 3 ++- exporter/cortexexporter/cortex_test.go | 3 ++- exporter/cortexexporter/testdata/config.yaml | 27 ++++++++------------ 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/exporter/cortexexporter/config.go b/exporter/cortexexporter/config.go index 6afe2a0077c..d78eba3d875 100644 --- a/exporter/cortexexporter/config.go +++ b/exporter/cortexexporter/config.go @@ -26,7 +26,6 @@ type Config struct { exporterhelper.TimeoutSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct. exporterhelper.QueueSettings `mapstructure:"sending_queue"` exporterhelper.RetrySettings `mapstructure:"retry_on_failure"` - // Namespace if set, exports metrics under the provided value. Namespace string `mapstructure:"namespace"` diff --git a/exporter/cortexexporter/cortex.go b/exporter/cortexexporter/cortex.go index d896b93daca..1fb789ada5f 100644 --- a/exporter/cortexexporter/cortex.go +++ b/exporter/cortexexporter/cortex.go @@ -32,11 +32,12 @@ import ( otlp "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/metrics/v1" ) - +// TODO: get default labels such as job or instance from Resource type cortexExporter struct { namespace string endpoint string client *http.Client + headers map[string]string wg *sync.WaitGroup closeChan chan struct{} } diff --git a/exporter/cortexexporter/cortex_test.go b/exporter/cortexexporter/cortex_test.go index cc6cd1538f2..f381c1935b8 100644 --- a/exporter/cortexexporter/cortex_test.go +++ b/exporter/cortexexporter/cortex_test.go @@ -41,8 +41,9 @@ import ( // "github.com/stretchr/testify/require" ) -// TODO: try to run Test_PushMetrics after export is in +// TODO: try to run Test_PushMetrics after export() is in // TODO: add bucket and histogram test cases for Test_PushMetrics +// TODO: check that NoError instead of NoNil is used at the right places //return false if descriptor type is nil func Test_validateMetrics(t *testing.T) { diff --git a/exporter/cortexexporter/testdata/config.yaml b/exporter/cortexexporter/testdata/config.yaml index 63e8eaa7184..765d4185d27 100644 --- a/exporter/cortexexporter/testdata/config.yaml +++ b/exporter/cortexexporter/testdata/config.yaml @@ -12,38 +12,31 @@ exporters: Prometheus-Remote-Write-Version: "0.1.0" Tenant-id: 234 another: "somevalue" + + namespace: "" + #A lot of this will be rewritten timeout: 10s reconnection_delay: 15 compression: "on" - num_workers: 4 - namespace: "prefix" - const_labels: - label1: value1 - label2: value2 + + basic_auth: #Nope username: "username" password: "1234" password_file: "yes" http_config: # CA certificate to validate API server certificate with. - http_endpoint: "localhost:8888" + endpoint: "localhost:8888" tls_config: ca_file: /var/lib/mycert.pem - read_buffer: - - write_buffer: + read_buffer_size: + write_buffer: + timeout: 5s # ServerName extension to indicate the name of the server. # https://tools.ietf.org/html/rfc4366#section-3. - - - - - - - - service: +service: pipelines: traces: receivers: [examplereceiver]