Skip to content

Commit b5057f5

Browse files
author
Paulo Janotti
authored
Add sfx receiver (#62)
* Add SignalFx Receiver Add a receiver supporting SignalFx metrics. * Run go mod tidy from top and signalfxreceiver * Few nits * Handle ENUM metrics * Add enpoint to config test * PR Feedback * Fix sapmexporter go.mod rebase * PR feedback
1 parent b96fcb0 commit b5057f5

13 files changed

+2337
-0
lines changed

receiver/signalfxreceiver/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../../Makefile.Common

receiver/signalfxreceiver/config.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package signalfxreceiver
16+
17+
import "github.com/open-telemetry/opentelemetry-collector/config/configmodels"
18+
19+
// Config defines configuration for the SignalFx receiver.
20+
type Config struct {
21+
configmodels.ReceiverSettings `mapstructure:",squash"`
22+
}
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package signalfxreceiver
16+
17+
import (
18+
"path"
19+
"testing"
20+
21+
"github.com/open-telemetry/opentelemetry-collector/config"
22+
"github.com/open-telemetry/opentelemetry-collector/config/configmodels"
23+
"github.com/stretchr/testify/assert"
24+
"github.com/stretchr/testify/require"
25+
)
26+
27+
func TestLoadConfig(t *testing.T) {
28+
factories, err := config.ExampleComponents()
29+
assert.Nil(t, err)
30+
31+
factory := &Factory{}
32+
factories.Receivers[typeStr] = factory
33+
cfg, err := config.LoadConfigFile(
34+
t, path.Join(".", "testdata", "config.yaml"), factories,
35+
)
36+
37+
require.NoError(t, err)
38+
require.NotNil(t, cfg)
39+
40+
assert.Equal(t, len(cfg.Receivers), 2)
41+
42+
r0 := cfg.Receivers["signalfx"]
43+
assert.Equal(t, r0, factory.CreateDefaultConfig())
44+
45+
r1 := cfg.Receivers["signalfx/allsettings"].(*Config)
46+
assert.Equal(t, r1,
47+
&Config{
48+
ReceiverSettings: configmodels.ReceiverSettings{
49+
TypeVal: typeStr,
50+
NameVal: "signalfx/allsettings",
51+
Endpoint: "localhost:8080",
52+
},
53+
})
54+
}

receiver/signalfxreceiver/doc.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package signalfxreceiver implements a receiver that can be used by the
16+
// OpenTelemetry collector to receive data in the SignalFx supported formats.
17+
package signalfxreceiver

receiver/signalfxreceiver/factory.go

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package signalfxreceiver
16+
17+
import (
18+
"context"
19+
20+
"github.com/open-telemetry/opentelemetry-collector/config/configerror"
21+
"github.com/open-telemetry/opentelemetry-collector/config/configmodels"
22+
"github.com/open-telemetry/opentelemetry-collector/consumer"
23+
"github.com/open-telemetry/opentelemetry-collector/receiver"
24+
"go.uber.org/zap"
25+
)
26+
27+
// This file implements factory for SignalFx receiver.
28+
29+
const (
30+
// The value of "type" key in configuration.
31+
typeStr = "signalfx"
32+
)
33+
34+
// Factory is the factory for SignalFx receiver.
35+
type Factory struct {
36+
}
37+
38+
var _ receiver.Factory = (*Factory)(nil)
39+
40+
// Type gets the type of the Receiver config created by this factory.
41+
func (f *Factory) Type() string {
42+
return typeStr
43+
}
44+
45+
// CustomUnmarshaler returns nil because we don't need custom unmarshaling for this config.
46+
func (f *Factory) CustomUnmarshaler() receiver.CustomUnmarshaler {
47+
return nil
48+
}
49+
50+
// CreateDefaultConfig creates the default configuration for Jaeger receiver.
51+
func (f *Factory) CreateDefaultConfig() configmodels.Receiver {
52+
return &Config{
53+
ReceiverSettings: configmodels.ReceiverSettings{
54+
TypeVal: typeStr,
55+
NameVal: typeStr,
56+
},
57+
}
58+
}
59+
60+
// CreateTraceReceiver creates a trace receiver based on provided config.
61+
func (f *Factory) CreateTraceReceiver(
62+
ctx context.Context,
63+
logger *zap.Logger,
64+
cfg configmodels.Receiver,
65+
consumer consumer.TraceConsumer,
66+
) (receiver.TraceReceiver, error) {
67+
68+
return nil, configerror.ErrDataTypeIsNotSupported
69+
}
70+
71+
// CreateMetricsReceiver creates a metrics receiver based on provided config.
72+
func (f *Factory) CreateMetricsReceiver(
73+
logger *zap.Logger,
74+
cfg configmodels.Receiver,
75+
consumer consumer.MetricsConsumer,
76+
) (receiver.MetricsReceiver, error) {
77+
78+
rCfg := cfg.(*Config)
79+
return New(logger, *rCfg, consumer)
80+
}
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2019, OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package signalfxreceiver
16+
17+
import (
18+
"context"
19+
"testing"
20+
21+
"github.com/open-telemetry/opentelemetry-collector/config/configcheck"
22+
"github.com/open-telemetry/opentelemetry-collector/config/configerror"
23+
"github.com/open-telemetry/opentelemetry-collector/consumer"
24+
"github.com/open-telemetry/opentelemetry-collector/consumer/consumerdata"
25+
"github.com/stretchr/testify/assert"
26+
"go.uber.org/zap"
27+
)
28+
29+
func TestCreateDefaultConfig(t *testing.T) {
30+
factory := &Factory{}
31+
cfg := factory.CreateDefaultConfig()
32+
assert.NotNil(t, cfg, "failed to create default config")
33+
assert.NoError(t, configcheck.ValidateConfig(cfg))
34+
}
35+
36+
type mockMetricsConsumer struct {
37+
}
38+
39+
var _ (consumer.MetricsConsumer) = (*mockMetricsConsumer)(nil)
40+
41+
func (m *mockMetricsConsumer) ConsumeMetricsData(ctx context.Context, md consumerdata.MetricsData) error {
42+
return nil
43+
}
44+
45+
func TestCreateReceiver(t *testing.T) {
46+
factory := &Factory{}
47+
cfg := factory.CreateDefaultConfig().(*Config)
48+
cfg.Endpoint = "localhost:0" // Endpoint is required, not going to be used here.
49+
50+
tReceiver, err := factory.CreateMetricsReceiver(zap.NewNop(), cfg, &mockMetricsConsumer{})
51+
assert.Nil(t, err, "receiver creation failed")
52+
assert.NotNil(t, tReceiver, "receiver creation failed")
53+
54+
tReceiver, err = factory.CreateMetricsReceiver(zap.NewNop(), cfg, &mockMetricsConsumer{})
55+
assert.Nil(t, err, "receiver creation failed")
56+
assert.NotNil(t, tReceiver, "receiver creation failed")
57+
58+
mReceiver, err := factory.CreateTraceReceiver(context.Background(), zap.NewNop(), cfg, nil)
59+
assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported)
60+
assert.Nil(t, mReceiver)
61+
}

receiver/signalfxreceiver/go.mod

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver
2+
3+
go 1.12
4+
5+
require (
6+
github.com/census-instrumentation/opencensus-proto v0.2.1
7+
github.com/golang/protobuf v1.3.2
8+
github.com/gorilla/mux v1.7.3
9+
github.com/open-telemetry/opentelemetry-collector v0.2.1-0.20191209163440-5d463fe48816
10+
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter v0.0.0-20191211173639-c78990cbbb53
11+
github.com/signalfx/com_signalfx_metrics_protobuf v0.0.0-20190530013331-054be550cb49
12+
github.com/stretchr/testify v1.4.0
13+
go.opencensus.io v0.22.1
14+
go.uber.org/zap v1.13.0
15+
)

0 commit comments

Comments
 (0)