@@ -6,19 +6,17 @@ package prometheusreceiver // import "github.com/open-telemetry/opentelemetry-co
6
6
import (
7
7
"errors"
8
8
"fmt"
9
- "net/url"
10
9
"os"
11
10
"sort"
12
11
"strings"
13
- "time"
14
12
15
13
commonconfig "github.com/prometheus/common/config"
16
14
promconfig "github.com/prometheus/prometheus/config"
17
- promHTTP "github.com/prometheus/prometheus/discovery/http"
18
15
"github.com/prometheus/prometheus/discovery/kubernetes"
19
- "go.opentelemetry.io/collector/config/confighttp"
20
16
"go.opentelemetry.io/collector/confmap"
21
17
"gopkg.in/yaml.v2"
18
+
19
+ "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/targetallocator"
22
20
)
23
21
24
22
// Config defines configuration for Prometheus receiver.
@@ -37,7 +35,7 @@ type Config struct {
37
35
// ReportExtraScrapeMetrics - enables reporting of additional metrics for Prometheus client like scrape_body_size_bytes
38
36
ReportExtraScrapeMetrics bool `mapstructure:"report_extra_scrape_metrics"`
39
37
40
- TargetAllocator * TargetAllocator `mapstructure:"target_allocator"`
38
+ TargetAllocator * targetallocator. Config `mapstructure:"target_allocator"`
41
39
}
42
40
43
41
// Validate checks the receiver configuration is valid.
@@ -48,27 +46,6 @@ func (cfg *Config) Validate() error {
48
46
return nil
49
47
}
50
48
51
- type TargetAllocator struct {
52
- confighttp.ClientConfig `mapstructure:",squash"`
53
- Interval time.Duration `mapstructure:"interval"`
54
- CollectorID string `mapstructure:"collector_id"`
55
- HTTPSDConfig * PromHTTPSDConfig `mapstructure:"http_sd_config"`
56
- HTTPScrapeConfig * PromHTTPClientConfig `mapstructure:"http_scrape_config"`
57
- }
58
-
59
- func (cfg * TargetAllocator ) Validate () error {
60
- // ensure valid endpoint
61
- if _ , err := url .ParseRequestURI (cfg .Endpoint ); err != nil {
62
- return fmt .Errorf ("TargetAllocator endpoint is not valid: %s" , cfg .Endpoint )
63
- }
64
- // ensure valid collectorID without variables
65
- if cfg .CollectorID == "" || strings .Contains (cfg .CollectorID , "${" ) {
66
- return fmt .Errorf ("CollectorID is not a valid ID" )
67
- }
68
-
69
- return nil
70
- }
71
-
72
49
// PromConfig is a redeclaration of promconfig.Config because we need custom unmarshaling
73
50
// as prometheus "config" uses `yaml` tags.
74
51
type PromConfig promconfig.Config
@@ -126,43 +103,6 @@ func (cfg *PromConfig) Validate() error {
126
103
return nil
127
104
}
128
105
129
- // PromHTTPSDConfig is a redeclaration of promHTTP.SDConfig because we need custom unmarshaling
130
- // as prometheus "config" uses `yaml` tags.
131
- type PromHTTPSDConfig promHTTP.SDConfig
132
-
133
- var _ confmap.Unmarshaler = (* PromHTTPSDConfig )(nil )
134
-
135
- func (cfg * PromHTTPSDConfig ) Unmarshal (componentParser * confmap.Conf ) error {
136
- cfgMap := componentParser .ToStringMap ()
137
- if len (cfgMap ) == 0 {
138
- return nil
139
- }
140
- cfgMap ["url" ] = "http://placeholder" // we have to set it as else marshaling will fail
141
- return unmarshalYAML (cfgMap , (* promHTTP .SDConfig )(cfg ))
142
- }
143
-
144
- type PromHTTPClientConfig commonconfig.HTTPClientConfig
145
-
146
- var _ confmap.Unmarshaler = (* PromHTTPClientConfig )(nil )
147
-
148
- func (cfg * PromHTTPClientConfig ) Unmarshal (componentParser * confmap.Conf ) error {
149
- cfgMap := componentParser .ToStringMap ()
150
- if len (cfgMap ) == 0 {
151
- return nil
152
- }
153
- return unmarshalYAML (cfgMap , (* commonconfig .HTTPClientConfig )(cfg ))
154
- }
155
-
156
- func (cfg * PromHTTPClientConfig ) Validate () error {
157
- httpCfg := (* commonconfig .HTTPClientConfig )(cfg )
158
- if err := validateHTTPClientConfig (httpCfg ); err != nil {
159
- return err
160
- }
161
- // Prometheus UnmarshalYaml implementation by default calls Validate,
162
- // but it is safer to do it here as well.
163
- return httpCfg .Validate ()
164
- }
165
-
166
106
func unmarshalYAML (in map [string ]any , out any ) error {
167
107
yamlOut , err := yaml .Marshal (in )
168
108
if err != nil {
0 commit comments