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 a7e578e commit c430963
Show file tree
Hide file tree
Showing 33 changed files with 2,246 additions and 244 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
}
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
)
166 changes: 166 additions & 0 deletions internal/huawei/go.sum

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions receiver/huaweicloudcesreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"slices"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/ces/v1/model"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/huawei"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/receiver/scraperhelper"
"go.uber.org/multierr"
Expand Down Expand Up @@ -41,7 +41,7 @@ type Config struct {
// If Indices is empty, no indices will be scraped.
Indices []string `mapstructure:"indices"`
// Set of attributes used to configure huawei's CES SDK connection
HuaweiSessionConfig `mapstructure:",squash"`
huawei.HuaweiSessionConfig `mapstructure:",squash"`

// ProjectID is a string to reference project where metrics should be associated with.
// If ProjectID is not filled in, the SDK will automatically call the IAM service to query the project id corresponding to the region.
Expand All @@ -67,18 +67,6 @@ type Config struct {
BackOffConfig configretry.BackOffConfig `mapstructure:"retry_on_failure"`
}

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"`
}

var _ component.Config = (*Config)(nil)

// These valid periods are defined by CES API constraints: https://support.huaweicloud.com/intl/en-us/api-ces/ces_03_0034.html#section3
Expand Down
87 changes: 44 additions & 43 deletions receiver/huaweicloudcesreceiver/go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/huaweicloudcesreceiver

go 1.22.0

toolchain go1.22.3
go 1.22.3

require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.110
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.113
github.com/open-telemetry/opentelemetry-collector-contrib/internal/huawei v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.108.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.107.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.108.1
go.opentelemetry.io/collector/config/confighttp v0.108.1
go.opentelemetry.io/collector/config/configopaque v1.14.1
go.opentelemetry.io/collector/config/configretry v1.13.0
go.opentelemetry.io/collector/confmap v1.14.1
go.opentelemetry.io/collector/consumer v0.108.1
go.opentelemetry.io/collector/consumer/consumertest v0.108.1
go.opentelemetry.io/collector/pdata v1.14.1
go.opentelemetry.io/collector/receiver v0.108.1
go.opentelemetry.io/collector/component v0.109.0
go.opentelemetry.io/collector/config/confighttp v0.109.0
go.opentelemetry.io/collector/config/configretry v1.15.0
go.opentelemetry.io/collector/confmap v1.15.0
go.opentelemetry.io/collector/consumer v0.109.0
go.opentelemetry.io/collector/consumer/consumertest v0.109.0
go.opentelemetry.io/collector/pdata v1.15.0
go.opentelemetry.io/collector/receiver v0.109.0
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
Expand Down Expand Up @@ -49,45 +47,48 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil v0.108.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.20.1 // indirect
github.com/prometheus/client_golang v1.20.2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/common v0.57.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rs/cors v1.11.0 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/tjfoc/gmsm v1.4.1 // indirect
go.mongodb.org/mongo-driver v1.15.0 // indirect
go.opentelemetry.io/collector v0.108.1 // indirect
go.opentelemetry.io/collector/client v1.14.1 // indirect
go.opentelemetry.io/collector/config/configauth v0.108.1 // indirect
go.opentelemetry.io/collector/config/configcompression v1.14.1 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.108.1 // indirect
go.opentelemetry.io/collector/config/configtls v1.14.1 // indirect
go.opentelemetry.io/collector/config/internal v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/extension v0.108.1 // indirect
go.opentelemetry.io/collector/extension/auth v0.108.1 // indirect
go.opentelemetry.io/collector/featuregate v1.14.1 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.107.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.50.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.65.0 // indirect
go.mongodb.org/mongo-driver v1.16.1 // indirect
go.opentelemetry.io/collector v0.109.0 // indirect
go.opentelemetry.io/collector/client v1.15.0 // indirect
go.opentelemetry.io/collector/config/configauth v0.109.0 // indirect
go.opentelemetry.io/collector/config/configcompression v1.15.0 // indirect
go.opentelemetry.io/collector/config/configopaque v1.15.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.109.0 // indirect
go.opentelemetry.io/collector/config/configtls v1.15.0 // indirect
go.opentelemetry.io/collector/config/internal v0.109.0 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.109.0 // indirect
go.opentelemetry.io/collector/extension v0.109.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.109.0 // indirect
go.opentelemetry.io/collector/featuregate v1.15.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.109.0 // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.109.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.51.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/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.66.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

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

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../pkg/pdatautil

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest
Expand Down
Loading

0 comments on commit c430963

Please sign in to comment.