forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
44 lines (34 loc) · 1.49 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package sqlserverreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver"
import (
"fmt"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/receiver/scraperhelper"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata"
)
// Config defines configuration for a sqlserver receiver.
type Config struct {
scraperhelper.ControllerConfig `mapstructure:",squash"`
metadata.MetricsBuilderConfig `mapstructure:",squash"`
InstanceName string `mapstructure:"instance_name"`
ComputerName string `mapstructure:"computer_name"`
// The following options currently do nothing. Functionality will be added in a future PR.
Password configopaque.String `mapstructure:"password"`
Port uint `mapstructure:"port"`
Server string `mapstructure:"server"`
Username string `mapstructure:"username"`
}
func (cfg *Config) Validate() error {
err := cfg.validateInstanceAndComputerName()
if err != nil {
return err
}
if !directDBConnectionEnabled(cfg) {
if cfg.Server != "" || cfg.Username != "" || string(cfg.Password) != "" {
return fmt.Errorf("Found one or more of the following configuration options set: [server, port, username, password]. " +
"All of these options must be configured to directly connect to a SQL Server instance.")
}
}
return nil
}