Skip to content

Commit

Permalink
Add headers field to exporter struct
Browse files Browse the repository at this point in the history
Yang
  • Loading branch information
huyan0 authored Aug 4, 2020
2 parents 4182996 + cf8fcaf commit c12bc77
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 25 deletions.
1 change: 0 additions & 1 deletion exporter/cortexexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
3 changes: 2 additions & 1 deletion exporter/cortexexporter/cortex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
9 changes: 5 additions & 4 deletions exporter/cortexexporter/cortex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ 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
// 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) {
Expand Down Expand Up @@ -569,7 +568,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))
Expand Down Expand Up @@ -646,6 +646,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)
Expand Down
3 changes: 3 additions & 0 deletions exporter/cortexexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 10 additions & 17 deletions exporter/cortexexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit c12bc77

Please sign in to comment.