Skip to content

Commit

Permalink
[tencentcloudlogserviceexporter]Simplify the endpoint configuration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wgliang authored Nov 8, 2021
1 parent 5d96ca0 commit 9c7899d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 41 deletions.
9 changes: 4 additions & 5 deletions exporter/tencentcloudlogserviceexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ package tencentcloudlogserviceexporter

import (
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confignet"
)

// Config defines configuration for TencentCloud Log Service exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"`
// LogService's Endpoint, https://cloud.tencent.com/document/product/614/18940
// for TencentCloud Kubernetes(or CVM), set ap-{region-id}.cls.tencentyun.com, eg ap-beijing.cls.tencentyun.com;
// others set ap-{region-id}.cls.tencentcs.com, eg ap-beijing.cls.tencentcs.com
confignet.TCPAddr `mapstructure:",squash"`
// LogService's Region, https://cloud.tencent.com/document/product/614/18940
// for TencentCloud Kubernetes(or CVM), set ap-{region}.cls.tencentyun.com, eg ap-beijing.cls.tencentyun.com;
// others set ap-{region}.cls.tencentcs.com, eg ap-beijing.cls.tencentcs.com
Region string `mapstructure:"region"`
// LogService's LogSet Name
LogSet string `mapstructure:"logset"`
// LogService's Topic Name
Expand Down
18 changes: 7 additions & 11 deletions exporter/tencentcloudlogserviceexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/config/configtest"
)

Expand All @@ -42,21 +41,18 @@ func TestLoadConfig(t *testing.T) {

// Endpoint doesn't have a default value so set it directly.
defaultCfg := factory.CreateDefaultConfig().(*Config)
defaultCfg.TCPAddr = confignet.TCPAddr{
Endpoint: "cls.ap-beijing.tencentcloudapi.com",
}
defaultCfg.Region = "ap-beijing"

assert.Equal(t, defaultCfg, e0)

e1 := cfg.Exporters[config.NewComponentIDWithName(typeStr, "2")]
expectedCfg := Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "2")),
TCPAddr: confignet.TCPAddr{
Endpoint: "cls.ap-beijing.tencentcloudapi.com",
},
LogSet: "demo-logset",
Topic: "demo-topic",
SecretID: "demo-secret-id",
SecretKey: "demo-secret-key",
Region: "ap-beijing",
LogSet: "demo-logset",
Topic: "demo-topic",
SecretID: "demo-secret-id",
SecretKey: "demo-secret-key",
}
assert.Equal(t, &expectedCfg, e1)

Expand Down
21 changes: 8 additions & 13 deletions exporter/tencentcloudlogserviceexporter/example/config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
receivers:
prometheus:
config:
scrape_configs:
- job_name: 'otel-collector'
scrape_interval: 10s
static_configs:
- targets: ['localhost:8890']
- targets: ['localhost:8889']
- targets: ['localhost:8888']
otlp:
protocols:
grpc:
endpoint: ":4317"

exporters:
tencentcloud_logservice:
# LogService's Endpoint, https://cloud.tencent.com/document/product/614/18940
# set cls.{region-id}.tencentcloudapi.com, eg cls.ap-beijing.tencentcloudapi.com;
endpoint: "cls.ap-beijing.tencentcloudapi.com"
# LogService's Region, https://cloud.tencent.com/document/product/614/18940
# set cls.{region}.tencentcloudapi.com, eg cls.ap-beijing.tencentcloudapi.com;
region: "ap-beijing"
# LogService's LogSet ID
logset: "demo-logset"
# LogService's Topic ID
Expand All @@ -26,5 +21,5 @@ exporters:
service:
pipelines:
metrics:
receivers: [prometheus]
receivers: [otlp]
exporters: [tencentcloud_logservice]
9 changes: 3 additions & 6 deletions exporter/tencentcloudlogserviceexporter/logs_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/model/pdata"
conventions "go.opentelemetry.io/collector/model/semconv/v1.5.0"
)
Expand Down Expand Up @@ -53,11 +52,9 @@ func createSimpleLogData(numberOfLogs int) pdata.Logs {
func TestNewLogsExporter(t *testing.T) {
got, err := newLogsExporter(componenttest.NewNopExporterCreateSettings(), &Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
TCPAddr: confignet.TCPAddr{
Endpoint: "cls.ap-beijing.tencentcloudapi.com",
},
LogSet: "demo-logset",
Topic: "demo-topic",
Region: "ap-beijing",
LogSet: "demo-logset",
Topic: "demo-topic",
})
assert.NoError(t, err)
require.NotNil(t, got)
Expand Down
4 changes: 2 additions & 2 deletions exporter/tencentcloudlogserviceexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ processors:

exporters:
tencentcloud_logservice:
endpoint: "cls.ap-beijing.tencentcloudapi.com"
region: "ap-beijing"
tencentcloud_logservice/2:
endpoint: "cls.ap-beijing.tencentcloudapi.com"
region: "ap-beijing"
# LogService's LogSet ID
logset: "demo-logset"
# LogService's Topic ID
Expand Down
7 changes: 3 additions & 4 deletions exporter/tencentcloudlogserviceexporter/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions"
"go.uber.org/zap"
pb "google.golang.org/protobuf/proto"

Expand All @@ -45,8 +44,8 @@ type logServiceClientImpl struct {

// newLogServiceClient Create Log Service client
func newLogServiceClient(config *Config, logger *zap.Logger) (logServiceClient, error) {
if config == nil || config.TCPAddr.Endpoint == "" || config.LogSet == "" || config.Topic == "" {
return nil, errors.New("missing logservice params: TCPAddr, LogSet, Topic")
if config == nil || config.Region == "" || config.LogSet == "" || config.Topic == "" {
return nil, errors.New("missing logservice params: Region, LogSet, Topic")
}

var credential *common.Credential
Expand All @@ -59,7 +58,7 @@ func newLogServiceClient(config *Config, logger *zap.Logger) (logServiceClient,
}

c := &logServiceClientImpl{
clientInstance: common.NewCommonClient(credential, regions.Beijing, profile.NewClientProfile()),
clientInstance: common.NewCommonClient(credential, config.Region, profile.NewClientProfile()),
logset: config.LogSet,
topic: config.Topic,
logger: logger,
Expand Down

0 comments on commit 9c7899d

Please sign in to comment.