forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add huaweicloudlogsreceiver skelethon
- Loading branch information
narcis.gemene
committed
Sep 11, 2024
1 parent
a7e578e
commit e06eae3
Showing
36 changed files
with
2,261 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../../Makefile.Common |
15 changes: 14 additions & 1 deletion
15
...uaweicloudcesreceiver/internal/backoff.go → internal/huawei/backoff.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...cloudcesreceiver/internal/backoff_test.go → internal/huawei/backoff_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package huawei | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tj/assert" | ||
) | ||
|
||
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.