Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
irisgve committed Oct 18, 2020
2 parents 2c33fbb + 1a20922 commit b1da8f8
Show file tree
Hide file tree
Showing 47 changed files with 1,606 additions and 203 deletions.
4 changes: 4 additions & 0 deletions exporter/datadogexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ datadog:
The hostname, environment, service and version can be set in the configuration for unified service tagging.

See the sample configuration file under the `example` folder for other available options.

## Trace Export Configuration

_Note: Trace Export is not supported on windows at the moment_
9 changes: 3 additions & 6 deletions exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ go 1.15
require (
github.com/DataDog/datadog-agent v0.0.0-20200417180928-f454c60bc16f
github.com/DataDog/viper v1.8.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.3.0
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
github.com/gogo/protobuf v1.3.1
github.com/klauspost/compress v1.10.10
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/stretchr/testify v1.6.1
github.com/zorkian/go-datadog-api v2.29.0+incompatible // indirect
go.opencensus.io v0.22.4
go.opentelemetry.io/collector v0.12.1-0.20201012183541-526f34200197
go.uber.org/zap v1.16.0
gopkg.in/zorkian/go-datadog-api.v2 v2.29.0
go.opencensus.io v0.22.4
google.golang.org/protobuf v1.25.0
gopkg.in/DataDog/dd-trace-go.v1 v1.26.0
gopkg.in/zorkian/go-datadog-api.v2 v2.29.0
)
3 changes: 3 additions & 0 deletions exporter/datadogexporter/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand Down Expand Up @@ -1202,6 +1204,7 @@ golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPI
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028 h1:4+4C/Iv2U4fMZBiMCc98MG1In4gJY5YRhtpDNeDeHWs=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
Expand Down
2 changes: 2 additions & 0 deletions exporter/datadogexporter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !windows

package datadogexporter

import (
Expand Down
2 changes: 2 additions & 0 deletions exporter/datadogexporter/translate_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !windows

package datadogexporter

import (
Expand Down
2 changes: 2 additions & 0 deletions exporter/datadogexporter/translate_traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !windows

package datadogexporter

import (
Expand Down
2 changes: 1 addition & 1 deletion exporter/sapmexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func newSAPMExporter(cfg *Config, params component.ExporterCreateParams) (sapmEx

var tracker *Tracker

if !cfg.Correlation.Enabled {
if cfg.Correlation.Enabled {
tracker = NewTracker(cfg, params)
}

Expand Down
26 changes: 26 additions & 0 deletions exporter/sapmexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ func TestCreateTraceExporter(t *testing.T) {
assert.NoError(t, te.Shutdown(context.Background()), "trace exporter shutdown failed")
}

func TestCreateTraceExporterWithCorrelationEnabled(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Endpoint = "localhost:1234"
cfg.Correlation.Enabled = true
cfg.Correlation.Endpoint = "http://localhost"
params := component.ExporterCreateParams{Logger: zap.NewNop()}

te, err := newSAPMExporter(cfg, params)
assert.Nil(t, err)
assert.NotNil(t, te, "failed to create trace exporter")

assert.NotNil(t, te.tracker, "correlation tracker should have been set")
}

func TestCreateTraceExporterWithCorrelationDisabled(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Endpoint = "localhost:1234"
params := component.ExporterCreateParams{Logger: zap.NewNop()}

te, err := newSAPMExporter(cfg, params)
assert.Nil(t, err)
assert.NotNil(t, te, "failed to create trace exporter")

assert.Nil(t, te.tracker, "tracker correlation should not be created")
}

func TestCreateTraceExporterWithInvalidConfig(t *testing.T) {
config := &Config{}
params := component.ExporterCreateParams{Logger: zap.NewNop()}
Expand Down
5 changes: 0 additions & 5 deletions exporter/sapmexporter/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWso
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/Songmu/retry v0.1.0 h1:hPA5xybQsksLR/ry/+t/7cFajPW+dqjmjhzZhioBILA=
github.com/Songmu/retry v0.1.0/go.mod h1:7sXIW7eseB9fq0FUvigRcQMVLR9tuHI0Scok+rkpAuA=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
Expand Down Expand Up @@ -286,7 +285,6 @@ github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v0.1.0 h1:M1Tv3VzNlEHg6uyACnRdtrploV2P7wZqH8BoQMtz0cg=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
Expand Down Expand Up @@ -409,7 +407,6 @@ github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY=
github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
github.com/gogo/googleapis v1.3.0/go.mod h1:d+q1s/xVJxZGKWwC/6UfPIF33J+G1Tq4GYv9Y+Tg/EU=
github.com/gogo/googleapis v1.3.1 h1:CzMaKrvF6Qa7XtRii064vKBQiyvmY8H8vG1xa1/W1JA=
github.com/gogo/googleapis v1.3.1/go.mod h1:d+q1s/xVJxZGKWwC/6UfPIF33J+G1Tq4GYv9Y+Tg/EU=
github.com/gogo/googleapis v1.4.0 h1:zgVt4UpGxcqVOw97aRGxT4svlcmdK35fynLNctY32zI=
github.com/gogo/googleapis v1.4.0/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c=
Expand Down Expand Up @@ -1023,8 +1020,6 @@ github.com/signalfx/gomemcache v0.0.0-20180823214636-4f7ef64c72a9/go.mod h1:Ytb8
github.com/signalfx/sapm-proto v0.4.0/go.mod h1:x3gtwJ1GRejtkghB4nYpwixh2zqJrLbPU959ZNhM0Fk=
github.com/signalfx/sapm-proto v0.6.2 h1:2LtB8AUGVyP5lSlsaBjFTsHfZNK/zn+jzWl1tWwniRA=
github.com/signalfx/sapm-proto v0.6.2/go.mod h1:AHtWypa5paGVlvDjSZw9Bh5GLgS62ee2U0UcsrLlLhU=
github.com/signalfx/signalfx-agent/pkg/apm v0.0.0-20201005151249-ce1a2e0a25e7 h1:+KSSs1oE/YFmd487gpPk79OcFo51tEiFqadFoE3RVvg=
github.com/signalfx/signalfx-agent/pkg/apm v0.0.0-20201005151249-ce1a2e0a25e7/go.mod h1:pNaqfprM2bSCBhE8sTT2NtasSWEsIJbrmnIF0ap/Cvg=
github.com/signalfx/signalfx-agent/pkg/apm v0.0.0-20201009143858-d25fd073fb56 h1:XYBr6vxBtAufUs72S5LYkjCmCB7QM4kvX2jwufGCqhg=
github.com/signalfx/signalfx-agent/pkg/apm v0.0.0-20201009143858-d25fd073fb56/go.mod h1:pNaqfprM2bSCBhE8sTT2NtasSWEsIJbrmnIF0ap/Cvg=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down
2 changes: 1 addition & 1 deletion exporter/signalfxexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestCreateMetricsExporterWithDefaultTranslaitonRules(t *testing.T) {

// Validate that default translation rules are loaded
// Expected values has to be updated once default config changed
assert.Equal(t, 49, len(config.TranslationRules))
assert.Equal(t, 51, len(config.TranslationRules))
assert.Equal(t, translation.ActionRenameDimensionKeys, config.TranslationRules[0].Action)
assert.Equal(t, 33, len(config.TranslationRules[0].Mapping))
}
Expand Down
16 changes: 15 additions & 1 deletion exporter/signalfxexporter/translation/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,19 @@ translation_rules:
- action: copy_metrics
mapping:
system.filesystem.usage: disk.summary_total
- action: aggregate_metric
metric_name: disk.summary_total
aggregation_method: avg
without_dimensions:
- mode
- mountpoint
- action: aggregate_metric
metric_name: disk.summary_total
aggregation_method: sum
without_dimensions:
- state
- device
- type
# convert filesystem metrics
- action: split_metric
Expand All @@ -401,12 +408,19 @@ translation_rules:
# df_complex.used_total
- action: copy_metrics
mapping:
df_complex.used: df_complex.used_total
df_complex.used: df_complex.used_total
- action: aggregate_metric
metric_name: df_complex.used_total
aggregation_method: avg
without_dimensions:
- mode
- mountpoint
- action: aggregate_metric
metric_name: df_complex.used_total
aggregation_method: sum
without_dimensions:
- device
- type
# disk utilization
- action: calculate_new_metric
Expand Down
6 changes: 3 additions & 3 deletions exporter/splunkhecexporter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *client) pushTraceData(
return numDroppedSpans, nil
}

func (c *client) sendSplunkEvents(ctx context.Context, splunkEvents []*splunkEvent) error {
func (c *client) sendSplunkEvents(ctx context.Context, splunkEvents []*splunk.Event) error {
body, compressed, err := encodeBodyEvents(&c.zippers, splunkEvents, c.config.DisableCompression)
if err != nil {
return consumererror.Permanent(err)
Expand Down Expand Up @@ -173,7 +173,7 @@ func (c *client) pushLogData(ctx context.Context, ld pdata.Logs) (numDroppedLogs
return numDroppedLogs, nil
}

func encodeBodyEvents(zippers *sync.Pool, evs []*splunkEvent, disableCompression bool) (bodyReader io.Reader, compressed bool, err error) {
func encodeBodyEvents(zippers *sync.Pool, evs []*splunk.Event, disableCompression bool) (bodyReader io.Reader, compressed bool, err error) {
buf := new(bytes.Buffer)
encoder := json.NewEncoder(buf)
for _, e := range evs {
Expand All @@ -186,7 +186,7 @@ func encodeBodyEvents(zippers *sync.Pool, evs []*splunkEvent, disableCompression
return getReader(zippers, buf, disableCompression)
}

func encodeBody(zippers *sync.Pool, dps []*splunk.Metric, disableCompression bool) (bodyReader io.Reader, compressed bool, err error) {
func encodeBody(zippers *sync.Pool, dps []*splunk.Event, disableCompression bool) (bodyReader io.Reader, compressed bool, err error) {
buf := new(bytes.Buffer)
encoder := json.NewEncoder(buf)
for _, e := range dps {
Expand Down
6 changes: 3 additions & 3 deletions exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func TestInvalidJson(t *testing.T) {
syncPool := sync.Pool{New: func() interface{} {
return gzip.NewWriter(nil)
}}
evs := []*splunkEvent{
evs := []*splunk.Event{
{
Event: badEvent,
},
Expand All @@ -429,7 +429,7 @@ func TestInvalidJsonClient(t *testing.T) {
badEvent := badJSON{
Foo: math.Inf(1),
}
evs := []*splunkEvent{
evs := []*splunk.Event{
{
Event: badEvent,
},
Expand All @@ -454,6 +454,6 @@ func TestInvalidURLClient(t *testing.T) {
}},
config: &Config{},
}
err := c.sendSplunkEvents(context.Background(), []*splunkEvent{})
err := c.sendSplunkEvents(context.Background(), []*splunk.Event{})
assert.EqualError(t, err, "Permanent error: parse \"//in%20va%20lid\": invalid URL escape \"%20\"")
}
4 changes: 3 additions & 1 deletion exporter/splunkhecexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/pdata"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/splunk"
)

const (
Expand Down Expand Up @@ -105,7 +107,7 @@ func buildClient(options *exporterOptions, config *Config, logger *zap.Logger) *
"Connection": "keep-alive",
"Content-Type": "application/json",
"User-Agent": "OpenTelemetry-Collector Splunk Exporter/v0.0.1",
"Authorization": "Splunk " + config.Token,
"Authorization": splunk.SplunkHECTokenHeader + " " + config.Token,
},
config: config,
}
Expand Down
4 changes: 2 additions & 2 deletions exporter/splunkhecexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestConsumeMetricsData(t *testing.T) {
t.Fatal("Small batch should not be compressed")
}
firstPayload := strings.Split(string(body), "\n\r\n\r")[0]
var metric splunk.Metric
var metric splunk.Event
err = json.Unmarshal([]byte(firstPayload), &metric)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestConsumeLogsData(t *testing.T) {
t.Fatal("Small batch should not be compressed")
}
firstPayload := strings.Split(string(body), "\n\r\n\r")[0]
var event splunkEvent
var event splunk.Event
err = json.Unmarshal([]byte(firstPayload), &event)
if err != nil {
t.Fatal(err)
Expand Down
10 changes: 5 additions & 5 deletions exporter/splunkhecexporter/logdata_to_splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/splunk"
)

func logDataToSplunk(logger *zap.Logger, ld pdata.Logs, config *Config) ([]*splunkEvent, int) {
func logDataToSplunk(logger *zap.Logger, ld pdata.Logs, config *Config) ([]*splunk.Event, int) {
numDroppedLogs := 0
splunkEvents := make([]*splunkEvent, 0)
splunkEvents := make([]*splunk.Event, 0)
rls := ld.ResourceLogs()
for i := 0; i < rls.Len(); i++ {
rl := rls.At(i)
Expand Down Expand Up @@ -60,14 +60,14 @@ func logDataToSplunk(logger *zap.Logger, ld pdata.Logs, config *Config) ([]*splu
return splunkEvents, numDroppedLogs
}

func mapLogRecordToSplunkEvent(lr pdata.LogRecord, config *Config, logger *zap.Logger) *splunkEvent {
func mapLogRecordToSplunkEvent(lr pdata.LogRecord, config *Config, logger *zap.Logger) *splunk.Event {
if lr.Body().IsNil() {
return nil
}
var host string
var source string
var sourcetype string
fields := map[string]string{}
fields := map[string]interface{}{}
lr.Attributes().ForEach(func(k string, v pdata.AttributeValue) {
if v.Type() != pdata.AttributeValueSTRING {
logger.Debug("Failed to convert log record attribute value to Splunk property value, value is not a string", zap.String("key", k))
Expand Down Expand Up @@ -97,7 +97,7 @@ func mapLogRecordToSplunkEvent(lr pdata.LogRecord, config *Config, logger *zap.L
}

eventValue := convertAttributeValue(lr.Body(), logger)
return &splunkEvent{
return &splunk.Event{
Time: nanoTimestampToEpochMilliseconds(lr.Timestamp()),
Host: host,
Source: source,
Expand Down
Loading

0 comments on commit b1da8f8

Please sign in to comment.