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

Added default funcs for configgrpc #9969

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3b30152
Added new default funcs
AkhigbeEromo Apr 15, 2024
8fe2516
Added tests for new funs
AkhigbeEromo Apr 15, 2024
afb6521
updated .chloggen folder
AkhigbeEromo Apr 15, 2024
f8827c8
added tests for default funcs
AkhigbeEromo Apr 15, 2024
d3d97b5
Merge branch 'main' into Added-DefaultFuncs-for-configgrpc
AkhigbeEromo Apr 16, 2024
4162023
Updated tests to include assert
AkhigbeEromo Apr 16, 2024
90e0a72
Merge branch 'open-telemetry:main' into Added-DefaultFuncs-for-config…
AkhigbeEromo Apr 17, 2024
2c283d4
added test comment
AkhigbeEromo Apr 17, 2024
4a2eff2
Merge branch 'open-telemetry:main' into Added-DefaultFuncs-for-config…
AkhigbeEromo Apr 19, 2024
bc16c63
added auth to default files
AkhigbeEromo Apr 19, 2024
bea9372
Added some default funcs and tests
AkhigbeEromo Apr 19, 2024
5595ac6
Update config/configgrpc/configgrpc.go
AkhigbeEromo Apr 19, 2024
92781ee
Updated functions and added tests
AkhigbeEromo Apr 19, 2024
0177c31
remove comment
AkhigbeEromo Apr 19, 2024
9b5b496
fixed bugs
AkhigbeEromo Apr 19, 2024
361a889
updated tests
AkhigbeEromo Apr 20, 2024
fedc2ce
Merge branch 'main' into Added-DefaultFuncs-for-configgrpc
AkhigbeEromo Apr 20, 2024
d55016f
Merge branch 'main' into Added-DefaultFuncs-for-configgrpc
AkhigbeEromo Apr 23, 2024
32c46a9
updated test
AkhigbeEromo Apr 24, 2024
4af7782
Update config/configgrpc/configgrpc.go
AkhigbeEromo Apr 26, 2024
3029322
Merge branch 'main' into Added-DefaultFuncs-for-configgrpc
AkhigbeEromo Apr 26, 2024
7b7ef39
updated godocs
AkhigbeEromo Apr 26, 2024
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
25 changes: 25 additions & 0 deletions .chloggen/configgrpc-add-newdefault-funcs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: configgrpc

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Adds `NewDefault*` functions for all the config structs.

# One or more tracking issues or pull requests related to the change
issues: [9654]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [api]
30 changes: 30 additions & 0 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ type KeepaliveClientConfig struct {
PermitWithoutStream bool `mapstructure:"permit_without_stream"`
}

// NewDefaultKeepaliveClientConfig returns a new instance of KeepaliveClientConfig with default values.

AkhigbeEromo marked this conversation as resolved.
Show resolved Hide resolved
func NewDefaultKeepaliveClientConfig() *KeepaliveClientConfig {
return &KeepaliveClientConfig{
Time: time.Second * 10,
Timeout: time.Second * 10,
}
}

// ClientConfig defines common settings for a gRPC client configuration.
type ClientConfig struct {
// The target to which the exporter is going to send traces or metrics,
Expand Down Expand Up @@ -90,12 +99,26 @@ type ClientConfig struct {
Auth *configauth.Authentication `mapstructure:"auth"`
}

// NewDefaultClientConfig returns a new instance of ClientConfig with default values.
func NewDefaultClientConfig() *ClientConfig {
return &ClientConfig{
TLSSetting: configtls.NewDefaultClientConfig(),
Keepalive: NewDefaultKeepaliveClientConfig(),
}
}

// KeepaliveServerConfig is the configuration for keepalive.
type KeepaliveServerConfig struct {
ServerParameters *KeepaliveServerParameters `mapstructure:"server_parameters"`
EnforcementPolicy *KeepaliveEnforcementPolicy `mapstructure:"enforcement_policy"`
}

// NewDefaultKeepaliveServerConfig returns a new instance of KeepaliveServerConfig with default values.

AkhigbeEromo marked this conversation as resolved.
Show resolved Hide resolved
func NewDefaultKeepaliveServerConfig() *KeepaliveServerConfig {
return &KeepaliveServerConfig{}
AkhigbeEromo marked this conversation as resolved.
Show resolved Hide resolved
}

// KeepaliveServerParameters allow configuration of the keepalive.ServerParameters.
// The same default values as keepalive.ServerParameters are applicable and get applied by the server.
// See https://godoc.org/google.golang.org/grpc/keepalive#ServerParameters for details.
Expand Down Expand Up @@ -150,6 +173,13 @@ type ServerConfig struct {
IncludeMetadata bool `mapstructure:"include_metadata"`
}

// NewDefaultServerConfig returns a new instance of ServerConfig with default values.
func NewDefaultServerConfig() *ServerConfig {
return &ServerConfig{
Keepalive: NewDefaultKeepaliveServerConfig(),
}
}

// sanitizedEndpoint strips the prefix of either http:// or https:// from configgrpc.ClientConfig.Endpoint.
func (gcs *ClientConfig) sanitizedEndpoint() string {
switch {
Expand Down
41 changes: 41 additions & 0 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,47 @@ import (
"go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp"
)

func TestNewDefaultKeepaliveClientConfig(t *testing.T) {
AkhigbeEromo marked this conversation as resolved.
Show resolved Hide resolved
// Call the function to get a new instance of KeepaliveClientConfig
config := NewDefaultKeepaliveClientConfig()

// Check if the Time field has the default value of 10 seconds
expectedTime := time.Second * 10
if config.Time != expectedTime {
t.Errorf("Expected Time to be %v, but got %v", expectedTime, config.Time)
}

// Check if the Timeout field has the default value of 10 seconds
expectedTimeout := time.Second * 10
if config.Timeout != expectedTimeout {
t.Errorf("Expected Timeout to be %v, but got %v", expectedTimeout, config.Timeout)
}
AkhigbeEromo marked this conversation as resolved.
Show resolved Hide resolved
}

func TestNewDefaultClientConfig(t *testing.T) {
// Call the function to get a new instance of ClientConfig
config := NewDefaultClientConfig()
// Check if Keepalive field is initialized
if config.Keepalive == nil {
t.Error("Expected Keepalive to be initialized")
}
}
func TestNewDefaultKeepaliveServerConfig(t *testing.T) {
config := NewDefaultKeepaliveServerConfig()

if config == nil {
t.Error("Expected non-nil KeepaliveServerConfig, got nil")
}

}
func TestNewDefaultServerConfig(t *testing.T) {
config := NewDefaultServerConfig()

if config == nil {
t.Error("Expected non-nil ServerConfig, got nil")
}
}

// testBalancerBuilder facilitates testing validateBalancerName().
type testBalancerBuilder struct{}

Expand Down
Loading