Skip to content

Commit

Permalink
add huaweicloudlogsreceiver skelethon
Browse files Browse the repository at this point in the history
  • Loading branch information
narcis.gemene committed Sep 11, 2024
1 parent db04631 commit 23cdf81
Show file tree
Hide file tree
Showing 36 changed files with 2,146 additions and 108 deletions.
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -1381,3 +1381,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
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
57 changes: 57 additions & 0 deletions internal/huawei/client_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

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

import (
"net/url"
"strconv"

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

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
}
30 changes: 30 additions & 0 deletions internal/huawei/client_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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 23cdf81

Please sign in to comment.