-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore][receiver/sqlserver] Add direct connection config options (#32176
) **Description:** <Describe what has changed.> <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> This adds config options for direct connection to a SQL server instance. For the sake of PR size, this adds no functionality, it's simply config options and validation. **Link to tracking Issue:** <Issue number if applicable> This was originally part of #31915, but I'm breaking this out to make the original PR a more manageable size. #30297 **Testing:** <Describe what testing was performed and which tests were added.> Existing tests and added tests are all passing. **Documentation:** <Describe the documentation added.> No documentation on purpose. The added config options currently have no impact on functionality, so users shouldn't be aware of this, and shouldn't try to use them yet.
- Loading branch information
Showing
9 changed files
with
257 additions
and
11 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,10 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build !windows | ||
|
||
package sqlserverreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver" | ||
|
||
func (cfg *Config) validateInstanceAndComputerName() error { | ||
return 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,88 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build !windows | ||
|
||
package sqlserverreceiver | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/receiver/scraperhelper" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata" | ||
) | ||
|
||
func TestValidateOtherOS(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
cfg *Config | ||
expectedSuccess bool | ||
}{ | ||
{ | ||
desc: "valid config", | ||
cfg: &Config{ | ||
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
}, | ||
expectedSuccess: true, | ||
}, { | ||
desc: "valid config with no metric settings", | ||
cfg: &Config{ | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
}, | ||
expectedSuccess: true, | ||
}, | ||
{ | ||
desc: "default config is valid", | ||
cfg: createDefaultConfig().(*Config), | ||
expectedSuccess: true, | ||
}, | ||
{ | ||
desc: "valid config with both names set", | ||
cfg: &Config{ | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
ComputerName: "ComputerName", | ||
InstanceName: "InstanceName", | ||
}, | ||
expectedSuccess: true, | ||
}, | ||
{ | ||
desc: "valid config with instance_name but not computer_name", | ||
cfg: &Config{ | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
InstanceName: "InstanceName", | ||
}, | ||
expectedSuccess: true, | ||
}, | ||
{ | ||
desc: "valid config with computer_name but not instance_name", | ||
cfg: &Config{ | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
ComputerName: "ComputerName", | ||
}, | ||
expectedSuccess: true, | ||
}, | ||
{ | ||
desc: "valid config with both instance and computer name", | ||
cfg: &Config{ | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
ComputerName: "ComputerName", | ||
InstanceName: "InstanceName", | ||
}, | ||
expectedSuccess: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
if tc.expectedSuccess { | ||
require.NoError(t, component.ValidateConfig(tc.cfg)) | ||
} else { | ||
require.Error(t, component.ValidateConfig(tc.cfg)) | ||
} | ||
}) | ||
} | ||
} |
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,19 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build windows | ||
|
||
package sqlserverreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver" | ||
|
||
import "fmt" | ||
|
||
func (cfg *Config) validateInstanceAndComputerName() error { | ||
if cfg.InstanceName != "" && cfg.ComputerName == "" { | ||
return fmt.Errorf("'instance_name' may not be specified without 'computer_name'") | ||
} | ||
if cfg.InstanceName == "" && cfg.ComputerName != "" { | ||
return fmt.Errorf("'computer_name' may not be specified without 'instance_name'") | ||
} | ||
|
||
return 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,79 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build windows | ||
|
||
package sqlserverreceiver | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/receiver/scraperhelper" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata" | ||
) | ||
|
||
func TestValidateWindows(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
cfg *Config | ||
expectedSuccess bool | ||
}{ | ||
{ | ||
desc: "valid config", | ||
cfg: &Config{ | ||
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
}, | ||
expectedSuccess: true, | ||
}, { | ||
desc: "valid config with no metric settings", | ||
cfg: &Config{ | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
}, | ||
expectedSuccess: true, | ||
}, | ||
{ | ||
desc: "default config is valid", | ||
cfg: createDefaultConfig().(*Config), | ||
expectedSuccess: true, | ||
}, | ||
{ | ||
desc: "invalid config with computer_name but not instance_name", | ||
cfg: &Config{ | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
ComputerName: "ComputerName", | ||
}, | ||
expectedSuccess: false, | ||
}, | ||
{ | ||
desc: "invalid config with instance_name but not computer_name", | ||
cfg: &Config{ | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
InstanceName: "InstanceName", | ||
}, | ||
expectedSuccess: false, | ||
}, | ||
{ | ||
desc: "valid config with both names set", | ||
cfg: &Config{ | ||
ControllerConfig: scraperhelper.NewDefaultControllerConfig(), | ||
ComputerName: "ComputerName", | ||
InstanceName: "InstanceName", | ||
}, | ||
expectedSuccess: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
if tc.expectedSuccess { | ||
require.NoError(t, component.ValidateConfig(tc.cfg)) | ||
} else { | ||
require.Error(t, component.ValidateConfig(tc.cfg)) | ||
} | ||
}) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.