Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tencentcloudlogserviceexporter]Fix the specified data reporting area bug, and simplify the configuration #6135

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't actually need this property, as it will default to this value anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I prefer to declare the port configuration, the user may not know what the default configuration is.


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]
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
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 == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please create an issue to move this logic to the Validate function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

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