-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
config.go
99 lines (80 loc) · 2.81 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package observiqexporter
import (
"errors"
"net/url"
"os"
"github.com/google/uuid"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)
// Config object for observIQ exporter
type Config struct {
config.ExporterSettings `mapstructure:",squash"`
exporterhelper.TimeoutSettings `mapstructure:",squash"`
exporterhelper.QueueSettings `mapstructure:"sending_queue"`
exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
// TLS Settings for http client to use when sending logs to endpoint
TLSSetting configtls.TLSClientSetting `mapstructure:",squash"`
// API key for authenticating with ingestion endpoint (required if no SecretKey)
APIKey string `mapstructure:"api_key"`
// Secret key for authenticating with the ingestion endpoint (required if no APIKey)
SecretKey string `mapstructure:"secret_key"`
// Endpoint URL; Defines the ingestion endpoint (optional)
Endpoint string `mapstructure:"endpoint"`
// ID that identifies this agent (optional)
AgentID string `mapstructure:"agent_id"`
// Name that identifies this agent (optional)
AgentName string `mapstructure:"agent_name"`
}
func (c *Config) validateConfig() error {
if c.APIKey == "" && c.SecretKey == "" {
return errors.New("api_key or secret_key must be specified")
}
if c.APIKey != "" && c.SecretKey != "" {
return errors.New("only one of api_key OR secret_key can be specified, not both")
}
if c.Endpoint == "" {
return errors.New("endpoint must not be empty")
}
url, urlParseError := url.Parse(c.Endpoint)
if urlParseError != nil {
return urlParseError
}
if url.Scheme != "http" && url.Scheme != "https" {
return errors.New("url scheme must be http or https")
}
return nil
}
// Default agent name will be the hostname
func defaultAgentName() string {
const fallbackAgentName = "otel collector"
hn, err := os.Hostname()
if err != nil {
return fallbackAgentName
}
return hn
}
// Default agent ID will be UUID based off hostname
func defaultAgentID() string {
const fallbackID = "00000000-0000-0000-0000-000000000000"
hn, err := os.Hostname()
if err != nil {
return fallbackID
}
id := uuid.NewMD5(uuid.Nil, []byte(hn))
return id.String()
}