-
Notifications
You must be signed in to change notification settings - Fork 807
Add multi-target support #1063
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
Merged
sysadmind
merged 26 commits into
prometheus-community:master
from
pincher95:add-multi-target-support
Aug 19, 2025
Merged
Add multi-target support #1063
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
aad3e72
Add multi-target support
pincher95 0a54b3f
Update example-prometheus.yml
pincher95 a5d0942
Make `es.uri` optional by setting default to empty string check if it…
pincher95 5957b0d
Update README.md
pincher95 90609cc
Add sanity target scheme validation
pincher95 1c08e68
Change yaml package to go.yaml.in/yaml/v3
pincher95 daecd52
Update yaml package to go.yaml.in/yaml/v3
pincher95 58d2965
Update CHANGELOG.md
pincher95 bd4e1c4
Remove whitespaces from README.md
pincher95 d77cf8e
Add testing for apikey authentication module
pincher95 d329fb3
Add Load-time validation for the auth module config file during startup
pincher95 5f754b7
Expose error in the logger
pincher95 4a660de
Add TLS config per target support
pincher95 5e32ad8
Indices and Shards collectors now fetch cluster_name once from GET / …
pincher95 d674f6d
Removed the special-case logic that redirected /metrics?target= reque…
pincher95 9fa0610
Add license headers to all new files
pincher95 d5f818b
Fixes for relative paths in multi-target mode
pincher95 750e0da
Bump github.com/prometheus/client_golang from 1.22.0 to 1.23.0 (#1065)
dependabot[bot] 3ea24f0
Add target schema validation, http/https only
pincher95 03d1a70
Cleanup
pincher95 b096536
Fix tls auth type validation
pincher95 236586c
Remove aws.region validation
pincher95 bd1c0a8
Add temp file cleanup in config_test.go
pincher95 76186e8
Merge branch 'master' into add-multi-target-support
pincher95 c7ca445
Add copyright header to config_test.go
pincher95 438cc76
Add version metric to the per-probe registry
pincher95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,139 @@ | ||
| // Copyright The Prometheus 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 config | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "go.yaml.in/yaml/v3" | ||
| ) | ||
|
|
||
| // Config represents the YAML configuration file structure. | ||
| type Config struct { | ||
| AuthModules map[string]AuthModule `yaml:"auth_modules"` | ||
| } | ||
|
|
||
| type AuthModule struct { | ||
| Type string `yaml:"type"` | ||
| UserPass *UserPassConfig `yaml:"userpass,omitempty"` | ||
| APIKey string `yaml:"apikey,omitempty"` | ||
| AWS *AWSConfig `yaml:"aws,omitempty"` | ||
| TLS *TLSConfig `yaml:"tls,omitempty"` | ||
| Options map[string]string `yaml:"options,omitempty"` | ||
| } | ||
|
|
||
| // AWSConfig contains settings for SigV4 authentication. | ||
| type AWSConfig struct { | ||
| Region string `yaml:"region"` | ||
| RoleARN string `yaml:"role_arn,omitempty"` | ||
| } | ||
|
|
||
| // TLSConfig allows per-target TLS options. | ||
| type TLSConfig struct { | ||
| CAFile string `yaml:"ca_file,omitempty"` | ||
| CertFile string `yaml:"cert_file,omitempty"` | ||
| KeyFile string `yaml:"key_file,omitempty"` | ||
| InsecureSkipVerify bool `yaml:"insecure_skip_verify,omitempty"` | ||
| } | ||
|
|
||
| type UserPassConfig struct { | ||
| Username string `yaml:"username"` | ||
| Password string `yaml:"password"` | ||
| } | ||
|
|
||
| // validate ensures every auth module has the required fields according to its type. | ||
| func (c *Config) validate() error { | ||
| for name, am := range c.AuthModules { | ||
| // Validate fields based on auth type | ||
| switch strings.ToLower(am.Type) { | ||
| case "userpass": | ||
| if am.UserPass == nil || am.UserPass.Username == "" || am.UserPass.Password == "" { | ||
| return fmt.Errorf("auth_module %s type userpass requires username and password", name) | ||
| } | ||
| case "apikey": | ||
| if am.APIKey == "" { | ||
| return fmt.Errorf("auth_module %s type apikey requires apikey", name) | ||
| } | ||
| case "aws": | ||
| if am.AWS == nil { | ||
| return fmt.Errorf("auth_module %s type aws requires region", name) | ||
| } | ||
| case "tls": | ||
| // TLS auth type means client certificate authentication only (no other auth) | ||
| if am.TLS == nil { | ||
| return fmt.Errorf("auth_module %s type tls requires tls configuration section", name) | ||
| } | ||
| if am.TLS.CertFile == "" || am.TLS.KeyFile == "" { | ||
| return fmt.Errorf("auth_module %s type tls requires cert_file and key_file for client certificate authentication", name) | ||
| } | ||
| // Validate that other auth fields are not set when using TLS auth type | ||
| if am.UserPass != nil { | ||
| return fmt.Errorf("auth_module %s type tls cannot have userpass configuration", name) | ||
| } | ||
| if am.APIKey != "" { | ||
| return fmt.Errorf("auth_module %s type tls cannot have apikey", name) | ||
| } | ||
| if am.AWS != nil { | ||
| return fmt.Errorf("auth_module %s type tls cannot have aws configuration", name) | ||
| } | ||
| default: | ||
| return fmt.Errorf("auth_module %s has unsupported type %s", name, am.Type) | ||
| } | ||
|
|
||
| // Validate TLS configuration (optional for all auth types, provides transport security) | ||
| if am.TLS != nil { | ||
| // For cert-based auth (type: tls), cert and key are required | ||
| // For other auth types, TLS config is optional and used for transport security | ||
| if strings.ToLower(am.Type) != "tls" { | ||
| // For non-TLS auth types, if cert/key are provided, both must be present | ||
| if (am.TLS.CertFile != "") != (am.TLS.KeyFile != "") { | ||
| return fmt.Errorf("auth_module %s: if providing client certificate, both cert_file and key_file must be specified", name) | ||
| } | ||
| } | ||
|
|
||
| // Validate file accessibility | ||
| for fileType, path := range map[string]string{ | ||
| "ca_file": am.TLS.CAFile, | ||
| "cert_file": am.TLS.CertFile, | ||
| "key_file": am.TLS.KeyFile, | ||
| } { | ||
| if path == "" { | ||
| continue | ||
| } | ||
| if _, err := os.Stat(path); err != nil { | ||
| return fmt.Errorf("auth_module %s: %s '%s' not accessible: %w", name, fileType, path, err) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // LoadConfig reads, parses, and validates the YAML config file. | ||
| func LoadConfig(path string) (*Config, error) { | ||
| data, err := os.ReadFile(path) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| var cfg Config | ||
| if err := yaml.Unmarshal(data, &cfg); err != nil { | ||
| return nil, err | ||
| } | ||
| if err := cfg.validate(); err != nil { | ||
| return nil, err | ||
| } | ||
| return &cfg, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.