-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into basic-auth-for-web-ui
- Loading branch information
Showing
161 changed files
with
2,515 additions
and
715 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
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
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
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
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,94 @@ | ||
package ovhcloud | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/grafana/agent/component" | ||
"github.com/grafana/agent/component/discovery" | ||
"github.com/grafana/river/rivertypes" | ||
"github.com/prometheus/common/config" | ||
"github.com/prometheus/common/model" | ||
prom_discovery "github.com/prometheus/prometheus/discovery/ovhcloud" | ||
) | ||
|
||
func init() { | ||
component.Register(component.Registration{ | ||
Name: "discovery.ovhcloud", | ||
Args: Arguments{}, | ||
Exports: discovery.Exports{}, | ||
|
||
Build: func(opts component.Options, args component.Arguments) (component.Component, error) { | ||
return New(opts, args.(Arguments)) | ||
}, | ||
}) | ||
} | ||
|
||
// Arguments configure the discovery.ovhcloud component. | ||
type Arguments struct { | ||
Endpoint string `river:"endpoint,attr,optional"` | ||
ApplicationKey string `river:"application_key,attr"` | ||
ApplicationSecret rivertypes.Secret `river:"application_secret,attr"` | ||
ConsumerKey rivertypes.Secret `river:"consumer_key,attr"` | ||
RefreshInterval time.Duration `river:"refresh_interval,attr,optional"` | ||
Service string `river:"service,attr"` | ||
} | ||
|
||
// DefaultArguments is used to initialize default values for Arguments. | ||
var DefaultArguments = Arguments{ | ||
Endpoint: "ovh-eu", | ||
RefreshInterval: 60 * time.Second, | ||
} | ||
|
||
// SetToDefault implements river.Defaulter. | ||
func (args *Arguments) SetToDefault() { | ||
*args = DefaultArguments | ||
} | ||
|
||
// Validate implements river.Validator. | ||
func (args *Arguments) Validate() error { | ||
if args.Endpoint == "" { | ||
return fmt.Errorf("endpoint cannot be empty") | ||
} | ||
|
||
if args.ApplicationKey == "" { | ||
return fmt.Errorf("application_key cannot be empty") | ||
} | ||
|
||
if args.ApplicationSecret == "" { | ||
return fmt.Errorf("application_secret cannot be empty") | ||
} | ||
|
||
if args.ConsumerKey == "" { | ||
return fmt.Errorf("consumer_key cannot be empty") | ||
} | ||
|
||
switch args.Service { | ||
case "dedicated_server", "vps": | ||
// Valid value - do nothing. | ||
default: | ||
return fmt.Errorf("unknown service: %v", args.Service) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Convert returns the upstream configuration struct. | ||
func (args *Arguments) Convert() *prom_discovery.SDConfig { | ||
return &prom_discovery.SDConfig{ | ||
Endpoint: args.Endpoint, | ||
ApplicationKey: args.ApplicationKey, | ||
ApplicationSecret: config.Secret(args.ApplicationSecret), | ||
ConsumerKey: config.Secret(args.ConsumerKey), | ||
RefreshInterval: model.Duration(args.RefreshInterval), | ||
Service: args.Service, | ||
} | ||
} | ||
|
||
// New returns a new instance of a discovery.ovhcloud component. | ||
func New(opts component.Options, args Arguments) (*discovery.Component, error) { | ||
return discovery.New(opts, args, func(args component.Arguments) (discovery.Discoverer, error) { | ||
newArgs := args.(Arguments) | ||
return prom_discovery.NewDiscovery(newArgs.Convert(), opts.Logger) | ||
}) | ||
} |
Oops, something went wrong.