Skip to content

Commit

Permalink
add huaweicloudlogsreceiver skelethon
Browse files Browse the repository at this point in the history
  • Loading branch information
narcis.gemene authored and narcis96 committed Sep 13, 2024
1 parent db04631 commit 74988e9
Show file tree
Hide file tree
Showing 39 changed files with 2,172 additions and 126 deletions.
4 changes: 4 additions & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ receivers:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudlogsreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/influxdbreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/iisreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.108.0
Expand Down Expand Up @@ -260,6 +261,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver => ../../receiver/haproxyreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver => ../../receiver/httpcheckreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver => ../../receiver/huaweicloudcesreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudlogsreceiver => ../../receiver/huaweicloudlogsreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/dockerobserver => ../../extension/observer/dockerobserver
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/k8sobserver => ../../extension/observer/k8sobserver
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sentryexporter => ../../exporter/sentryexporter
Expand Down Expand Up @@ -502,4 +504,6 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/exporter/rabbitmqexporter => ../../exporter/rabbitmqexporter
- github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver => ../../receiver/githubreceiver
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/grpcutil => ../../internal/grpcutil
- github.com/open-telemetry/opentelemetry-collector-contrib/internal/huawei => ../../internal/huawei


3 changes: 3 additions & 0 deletions cmd/otelcontribcol/components.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

module github.com/open-telemetry/opentelemetry-collector-contrib/cmd/otelcontribcol

go 1.22.0

toolchain go1.22.7
go 1.22.3

require (
github.com/open-telemetry/opentelemetry-collector-contrib/confmap/provider/s3provider v0.108.0
Expand Down Expand Up @@ -155,6 +153,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudlogsreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/iisreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/influxdbreceiver v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/jaegerreceiver v0.108.0
Expand Down Expand Up @@ -645,6 +644,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/internal/exp/metrics v0.108.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter v0.108.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/grpcutil v0.108.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/huawei v0.108.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig v0.108.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka v0.108.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/kubelet v0.108.0 // indirect
Expand Down Expand Up @@ -810,7 +810,7 @@ require (
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.29.0 // indirect
go.opentelemetry.io/contrib/zpages v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.5.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.29.0 // indirect
Expand All @@ -822,11 +822,11 @@ require (
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.29.0 // indirect
go.opentelemetry.io/otel/log v0.5.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/log v0.5.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/dig v1.17.1 // indirect
Expand Down Expand Up @@ -900,6 +900,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpc

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver => ../../receiver/huaweicloudcesreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudlogsreceiver => ../../receiver/huaweicloudlogsreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/dockerobserver => ../../extension/observer/dockerobserver

replace github.com/open-telemetry/opentelemetry-collector-contrib/extension/observer/k8sobserver => ../../extension/observer/k8sobserver
Expand Down Expand Up @@ -1381,3 +1383,5 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/rabbi
replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/githubreceiver => ../../receiver/githubreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/grpcutil => ../../internal/grpcutil

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/huawei => ../../internal/huawei
12 changes: 6 additions & 6 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/huawei/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../Makefile.Common
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package internal // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver/internal"
package huawei // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/huawei"

import (
"context"
"fmt"
"time"

"github.com/cenkalti/backoff/v4"
"go.opentelemetry.io/collector/config/configretry"
"go.uber.org/zap"
)

func NewExponentialBackOff(backOffConfig *configretry.BackOffConfig) *backoff.ExponentialBackOff {
return &backoff.ExponentialBackOff{
InitialInterval: backOffConfig.InitialInterval,
RandomizationFactor: backOffConfig.RandomizationFactor,
Multiplier: backOffConfig.Multiplier,
MaxInterval: backOffConfig.MaxInterval,
MaxElapsedTime: backOffConfig.MaxElapsedTime,
Stop: backoff.Stop,
Clock: backoff.SystemClock,
}
}

// Generic function to make an API call with exponential backoff and context cancellation handling.
func MakeAPICallWithRetry[T any](
ctx context.Context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package internal
package huawei

import (
"context"
Expand Down
66 changes: 66 additions & 0 deletions internal/huawei/client_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package huawei // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/huawei"

import (
"errors"
"net/url"
"strconv"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/config"
"go.opentelemetry.io/collector/config/configopaque"
)

var (
// Predefined error responses for configuration validation failures
ErrMissingProjectID = errors.New(`"project_id" is not specified in config`)
ErrMissingRegionID = errors.New(`"region_id" is not specified in config`)

ErrInvalidProxy = errors.New(`"proxy_address" must be specified if "proxy_user" or "proxy_password" is set"`)
)

type HuaweiSessionConfig struct {
AccessKey configopaque.String `mapstructure:"access_key"`

SecretKey configopaque.String `mapstructure:"secret_key"`
// Number of seconds before timing out a request.
NoVerifySSL bool `mapstructure:"no_verify_ssl"`
// Upload segments to AWS X-Ray through a proxy.
ProxyAddress string `mapstructure:"proxy_address"`
ProxyUser string `mapstructure:"proxy_user"`
ProxyPassword string `mapstructure:"proxy_password"`
}

func CreateHTTPConfig(cfg HuaweiSessionConfig) (*config.HttpConfig, error) {
if cfg.ProxyAddress == "" {
return config.DefaultHttpConfig().WithIgnoreSSLVerification(cfg.NoVerifySSL), nil
}
proxy, err := configureHTTPProxy(cfg)
if err != nil {
return nil, err
}
return config.DefaultHttpConfig().WithProxy(proxy), nil
}

func configureHTTPProxy(cfg HuaweiSessionConfig) (*config.Proxy, error) {
proxyURL, err := url.Parse(cfg.ProxyAddress)
if err != nil {
return nil, err
}

proxy := config.NewProxy().
WithSchema(proxyURL.Scheme).
WithHost(proxyURL.Hostname())
if len(proxyURL.Port()) > 0 {
if i, err := strconv.Atoi(proxyURL.Port()); err == nil {
proxy = proxy.WithPort(i)
}
}

// Configure the username and password if the proxy requires authentication
if len(cfg.ProxyUser) > 0 {
proxy = proxy.WithUsername(cfg.ProxyUser).WithPassword(cfg.ProxyPassword)
}
return proxy, nil
}
33 changes: 33 additions & 0 deletions internal/huawei/client_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package huawei

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCreateHTTPConfigNoVerifySSL(t *testing.T) {
cfg, err := CreateHTTPConfig(HuaweiSessionConfig{NoVerifySSL: true})
require.NoError(t, err)
assert.True(t, cfg.IgnoreSSLVerification)
}

func TestCreateHTTPConfigWithProxy(t *testing.T) {
cfg, err := CreateHTTPConfig(HuaweiSessionConfig{
ProxyAddress: "https://127.0.0.1:8888",
ProxyUser: "admin",
ProxyPassword: "pass",
AccessKey: "123",
SecretKey: "secret",
})
require.NoError(t, err)
assert.Equal(t, "https", cfg.HttpProxy.Schema)
assert.Equal(t, "127.0.0.1", cfg.HttpProxy.Host)
assert.Equal(t, 8888, cfg.HttpProxy.Port)
assert.False(t, cfg.IgnoreSSLVerification)

}
19 changes: 19 additions & 0 deletions internal/huawei/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/internal/huawei

go 1.22.3

require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.113
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/config/configopaque v1.15.0
go.opentelemetry.io/collector/config/configretry v1.15.0
go.uber.org/zap v1.27.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 74988e9

Please sign in to comment.