Skip to content

Commit

Permalink
complete documentation about how to configure the metrics_usage
Browse files Browse the repository at this point in the history
Signed-off-by: Augustin Husson <[email protected]>
  • Loading branch information
Nexucis committed Oct 28, 2024
1 parent 47715cb commit 6e831e1
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 11 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ This collector gets the list of metrics for a defined period of time. This list

#### Configuration

See the doc for the complete configuration [here](./docs/configuration.md#metric_collector-config)

Example:

```yaml
metric_collector:
enable: true
Expand All @@ -87,6 +91,10 @@ This collector gets the Prometheus Rules Group using the HTTP API. Then it extra
#### Configuration
See the doc for the complete configuration [here](./docs/configuration.md#rules_collector-config)
Example:
```yaml
rules_collector:
enable: true
Expand All @@ -100,6 +108,10 @@ This collector gets the list of dashboards using the HTTP API of Perses. Then it
#### Configuration
See the doc for the complete configuration [here](./docs/configuration.md#perses_collector-config)
Example:
```yaml
perses_collector:
enable: true
Expand All @@ -114,6 +126,10 @@ Extraction from variable still needs to be done.
#### Configuration
See the doc for the complete configuration [here](./docs/configuration.md#grafana_collector-config)
Example:
```yaml
grafana_collector:
enable: true
Expand Down
29 changes: 21 additions & 8 deletions config/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func NewHTTPClient(cfg HTTPClient) (*http.Client, error) {
}

type MetricCollector struct {
Enable bool `yaml:"enable"`
Period model.Duration `yaml:"period,omitempty"`
PrometheusClient HTTPClient `yaml:"http_client"`
Enable bool `yaml:"enable"`
Period model.Duration `yaml:"period,omitempty"`
HTTPClient HTTPClient `yaml:"http_client"`
}

func (c *MetricCollector) Verify() error {
Expand All @@ -63,16 +63,16 @@ func (c *MetricCollector) Verify() error {
if c.Period <= 0 {
c.Period = model.Duration(defaultMetricCollectorPeriodDuration)
}
if c.PrometheusClient.URL == nil {
if c.HTTPClient.URL == nil {
return fmt.Errorf("missing Prometheus URL for the metric collector")
}
return nil
}

type RulesCollector struct {
Enable bool `yaml:"enable"`
Period model.Duration `yaml:"period,omitempty"`
PrometheusClient HTTPClient `yaml:"http_client"`
Enable bool `yaml:"enable"`
Period model.Duration `yaml:"period,omitempty"`
HTTPClient HTTPClient `yaml:"http_client"`
}

func (c *RulesCollector) Verify() error {
Expand All @@ -82,7 +82,7 @@ func (c *RulesCollector) Verify() error {
if c.Period <= 0 {
c.Period = model.Duration(defaultMetricCollectorPeriodDuration)
}
if c.PrometheusClient.URL == nil {
if c.HTTPClient.URL == nil {
return fmt.Errorf("missing Prometheus URL for the rules collector")
}
return nil
Expand Down Expand Up @@ -112,3 +112,16 @@ type GrafanaCollector struct {
Period model.Duration `yaml:"period,omitempty"`
HTTPClient HTTPClient `yaml:"http_client"`
}

func (c *GrafanaCollector) Verify() error {
if !c.Enable {
return nil
}
if c.Period <= 0 {
c.Period = model.Duration(defaultMetricCollectorPeriodDuration)
}
if c.HTTPClient.URL == nil {
return fmt.Errorf("missing Rest URL for the perses collector")
}
return nil
}
136 changes: 136 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
Configuration
=============

Metrics-usage is configured via command-line flags and a configuration file

## Flags available

```bash
-config string
Path to the yaml configuration file for the api. Configuration can be overridden when using the environment variable
-log.level string
log level. Possible value: panic, fatal, error, warning, info, debug, trace (default "info")
-log.method-trace
include the calling method as a field in the log. Can be useful to see immediately where the log comes from
-pprof
Enable pprof
-web.hide-port
If true, it won t be print on stdout the port listened to receive the HTTP request
-web.listen-address string
The address to listen on for HTTP requests, web interface and telemetry. (default ":8080")
-web.telemetry-path string
Path under which to expose metrics. (default "/metrics")
```

Example:

```bash
metrics-usage --config=./config.yaml --log.method-trace
```

## Configuration File

### Definition

The file is written in YAML format, defined by the scheme described below. Brackets indicate that a parameter is optional.

Generic placeholders are defined as follows:

* `<boolean>`: a boolean that can take the values `true` or `false`
* `<duration>`: a duration matching the regular expression `((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)`, e.g. `1d`, `1h30m`, `5m`, `10s`
* `<filename>`: a valid path in the current working directory
* `<path>`: a valid URL path
* `<int>`: an integer value
* `<secret>`: a regular string that is a secret, such as a password
* `<string>`: a regular string

```yaml
[ metric_collector: <Metric_Collector config> ]
[ rules_collector: <Rule_Collector config> ]
[ perses_collector: <Perses_Collector config> ]
[ grafana_collector: <Grafana_Collector config> ]
```
### Metric_Collector Config
```yaml
[ enable: <boolean> | default=false ]
[ period: <duration> | default="12h" ]
http_client: <HTTPClient config>
```
### Rules_Collector Config
```yaml
[ enable: <boolean> | default=false ]
[ period: <duration> | default="12h" ]
http_client: <HTTPClient config>
```
### Perses_Collector Config
```yaml
[ enable: <boolean> | default=false ]
[ period: <duration> | default="12h" ]
http_client:
url: <string>
[ tls_config: <TLS Config> ]
auth:
basic_auth:
username: <string>
[ password: <string> ]
[ password_file: <string> ]
[ oauth: < Oauth Config> ]
```
### Grafana_Collector Config
```yaml
[ enable: <boolean> | default=false ]
[ period: <duration> | default="12h" ]
http_client: < HTTPClient config>
```
### TLS Config
```yaml
# CA certificate to validate API server certificate with. At most one of ca and ca_file is allowed.
[ ca: <secret> ]
[ caFile: <filename> ]

# Certificate and key for client cert authentication to the server.
# At most one of cert and cert_file is allowed.
# At most one of key and key_file is allowed.
[ cert: <secret> ]
[ certFile: <filename> ]
[ key: <secret> ]
[ keyFile: <filename> ]

# ServerName extension to indicate the name of the server.
# https://tools.ietf.org/html/rfc4366#section-3.1
[ serverName: <string> ]

# Disable validation of the server certificate.
[ insecureSkipVerify: <boolean> | default = false ]
```
### HTTPClient Config
```yaml
url: <string>
[ oauth: < Oauth Config> ]
[ tls_config: < TLS Config> ]
```
### Oauth Config
```yaml
# ClientID is the application's ID.
client_id: <string>

# ClientSecret is the application's secret.
client_secret: <string>

# TokenURL is the resource server's token endpoint URL. This is a constant specific to each server.
token_url: <string>
```
2 changes: 1 addition & 1 deletion source/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func NewCollector(db database.Database, cfg config.MetricCollector) (async.SimpleTask, error) {
promClient, err := prometheus.NewClient(cfg.PrometheusClient)
promClient, err := prometheus.NewClient(cfg.HTTPClient)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions source/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
)

func NewCollector(db database.Database, cfg config.RulesCollector) (async.SimpleTask, error) {
promClient, err := prometheus.NewClient(cfg.PrometheusClient)
promClient, err := prometheus.NewClient(cfg.HTTPClient)
if err != nil {
return nil, err
}
return &rulesCollector{
client: promClient,
db: db,
promURL: cfg.PrometheusClient.URL.String(),
promURL: cfg.HTTPClient.URL.String(),
}, nil
}

Expand Down

0 comments on commit 6e831e1

Please sign in to comment.