Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Commit 231ed43

Browse files
Add implementation of OpenCensus exporter config
- Added factory and config loading for OpenCensus exporter. Note: the factory is not compelte yet. We will need to add ability to create the exporter based on its config. It will be done in a future PR. Testing done: automated tests
1 parent 7a7c903 commit 231ed43

File tree

5 files changed

+205
-0
lines changed

5 files changed

+205
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2019, OpenCensus 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 opencensusexporter
16+
17+
import (
18+
"time"
19+
20+
"github.com/census-instrumentation/opencensus-service/internal/configmodels"
21+
)
22+
23+
// ConfigV2 defines configuration for OpenCensus exporter.
24+
type ConfigV2 struct {
25+
configmodels.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
26+
Endpoint string `mapstructure:"endpoint"`
27+
Compression string `mapstructure:"compression"`
28+
Headers map[string]string `mapstructure:"headers"`
29+
NumWorkers int `mapstructure:"num-workers"`
30+
CertPemFile string `mapstructure:"cert-pem-file"`
31+
UseSecure bool `mapstructure:"secure,omitempty"`
32+
ReconnectionDelay time.Duration `mapstructure:"reconnection-delay,omitempty"`
33+
KeepaliveParameters *keepaliveConfig `mapstructure:"keepalive,omitempty"`
34+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2019, OpenCensus 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 opencensusexporter
16+
17+
import (
18+
"path"
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
"github.com/stretchr/testify/require"
23+
24+
"github.com/census-instrumentation/opencensus-service/internal/configmodels"
25+
"github.com/census-instrumentation/opencensus-service/internal/configv2"
26+
"github.com/census-instrumentation/opencensus-service/internal/factories"
27+
)
28+
29+
var _ = configv2.RegisterTestFactories()
30+
31+
func TestLoadConfig(t *testing.T) {
32+
factory := factories.GetExporterFactory(typeStr)
33+
34+
config, err := configv2.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"))
35+
36+
require.NoError(t, err)
37+
require.NotNil(t, config)
38+
39+
e0 := config.Exporters["opencensus"]
40+
assert.Equal(t, e0, factory.CreateDefaultConfig())
41+
42+
e1 := config.Exporters["opencensus/2"]
43+
assert.Equal(t, e1,
44+
&ConfigV2{
45+
ExporterSettings: configmodels.ExporterSettings{
46+
Enabled: true,
47+
},
48+
Headers: map[string]string{
49+
"can you have a . here?": "F0000000-0000-0000-0000-000000000000",
50+
"header1": "234",
51+
"another": "somevalue",
52+
},
53+
Endpoint: "1.2.3.4:1234",
54+
Compression: "on",
55+
NumWorkers: 123,
56+
CertPemFile: "/var/lib/mycert.pem",
57+
UseSecure: true,
58+
ReconnectionDelay: 15,
59+
KeepaliveParameters: &keepaliveConfig{
60+
Time: 20,
61+
PermitWithoutStream: true,
62+
Timeout: 30,
63+
},
64+
})
65+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2018, OpenCensus 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 opencensusexporter
16+
17+
import (
18+
"github.com/census-instrumentation/opencensus-service/internal/configmodels"
19+
"github.com/census-instrumentation/opencensus-service/internal/factories"
20+
)
21+
22+
var _ = factories.RegisterExporterFactory(&exporterFactory{})
23+
24+
const (
25+
// The value of "type" key in configuration.
26+
typeStr = "opencensus"
27+
)
28+
29+
// exporterFactory is the factory for OpenCensus exporter.
30+
type exporterFactory struct {
31+
}
32+
33+
// Type gets the type of the Exporter config created by this factory.
34+
func (f *exporterFactory) Type() string {
35+
return typeStr
36+
}
37+
38+
// CreateDefaultConfig creates the default configuration for exporter.
39+
func (f *exporterFactory) CreateDefaultConfig() configmodels.Exporter {
40+
return &ConfigV2{
41+
ExporterSettings: configmodels.ExporterSettings{},
42+
Headers: map[string]string{},
43+
}
44+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2018, OpenCensus 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 opencensusexporter
16+
17+
import (
18+
"testing"
19+
20+
"github.com/stretchr/testify/assert"
21+
"github.com/stretchr/testify/require"
22+
23+
"github.com/census-instrumentation/opencensus-service/internal/factories"
24+
)
25+
26+
func TestCreateDefaultConfig(t *testing.T) {
27+
factory := factories.GetExporterFactory(typeStr)
28+
require.NotNil(t, factory)
29+
30+
cfg := factory.CreateDefaultConfig()
31+
assert.NotNil(t, cfg, "failed to create default config")
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
receivers:
2+
examplereceiver:
3+
4+
processors:
5+
exampleprocessor:
6+
7+
exporters:
8+
opencensus:
9+
opencensus/2:
10+
enabled: true
11+
endpoint: "1.2.3.4:1234"
12+
compression: "on"
13+
num-workers: 123
14+
cert-pem-file: /var/lib/mycert.pem
15+
headers:
16+
"can you have a . here?": "F0000000-0000-0000-0000-000000000000"
17+
header1: 234
18+
another: "somevalue"
19+
secure: true
20+
reconnection-delay: 15
21+
keepalive:
22+
time: 20
23+
timeout: 30
24+
permit-without-stream: true
25+
26+
pipelines:
27+
traces:
28+
receivers: [examplereceiver]
29+
processors: [exampleprocessor]
30+
exporters: [opencensus]

0 commit comments

Comments
 (0)