diff --git a/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-disable-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-disable-usage.golden index 79e5c5fc75..ed7d6e8c2a 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-disable-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-disable-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-enable-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-enable-usage.golden index ed50b2d0c1..94faacef82 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-enable-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-enable-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-get-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-get-usage.golden index ffcef4d570..42f0802cb9 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-get-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-alert-manager-get-usage.golden @@ -19,3 +19,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-config-get-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-config-get-usage.golden index 478504d611..1a1cd2b55e 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-config-get-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-config-get-usage.golden @@ -4,6 +4,7 @@ Generate a ready-to-use configuration snippet for a Cockpit data source. Supported tools: - prometheus: generates a remote_write block for prometheus.yml (metrics data sources only). + - fluent-bit: generates a fluent-bit.conf snippet with a dummy input and an OpenTelemetry output (logs data sources only). Use generate-token=true to create a new Cockpit token and inject it directly in the snippet. The token is created with the minimum required write scope for the data source type. @@ -21,9 +22,15 @@ EXAMPLES: Generate a Prometheus remote_write snippet with a named token scw cockpit config get 11111111-1111-1111-1111-111111111111 type=prometheus generate-token=true token-name=my-prometheus + Generate a Fluent Bit configuration snippet + scw cockpit config get 11111111-1111-1111-1111-111111111111 type=fluent-bit + + Generate a Fluent Bit configuration snippet with a new token + scw cockpit config get 11111111-1111-1111-1111-111111111111 type=fluent-bit generate-token=true + ARGS: data-source-id ID of the data source to generate the configuration for - type Configuration template type (prometheus) + type Configuration template type (prometheus | fluent-bit) [generate-token] Create a new Cockpit token and inject it in the generated snippet [token-name=prometheus-push] Name of the token to create when generate-token=true [region=fr-par] Region to target. If none is passed will use default region from the config (fr-par | nl-ams | pl-waw) diff --git a/cmd/scw/testdata/test-all-usage-cockpit-contact-point-create-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-contact-point-create-usage.golden index 780c14a2d5..2a883bdcf8 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-contact-point-create-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-contact-point-create-usage.golden @@ -22,3 +22,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-contact-point-delete-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-contact-point-delete-usage.golden index 19e1449ec4..eaa22998fb 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-contact-point-delete-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-contact-point-delete-usage.golden @@ -19,3 +19,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-contact-point-list-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-contact-point-list-usage.golden index 895ae60c39..dfb11af0ca 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-contact-point-list-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-contact-point-list-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-data-source-create-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-data-source-create-usage.golden index 4b35b39d20..26030da747 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-data-source-create-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-data-source-create-usage.golden @@ -22,3 +22,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-data-source-delete-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-data-source-delete-usage.golden index 47cf631573..3943d41c3c 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-data-source-delete-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-data-source-delete-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-data-source-get-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-data-source-get-usage.golden index 192e01656d..f89db0c8e6 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-data-source-get-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-data-source-get-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-data-source-list-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-data-source-list-usage.golden index 1715cd8820..697eb69bec 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-data-source-list-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-data-source-list-usage.golden @@ -21,3 +21,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-data-source-update-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-data-source-update-usage.golden index c91801151b..53e0e3e405 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-data-source-update-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-data-source-update-usage.golden @@ -20,3 +20,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-grafana-get-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-grafana-get-usage.golden index a180d13bed..0c73a7c839 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-grafana-get-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-grafana-get-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-grafana-sync-data-sources-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-grafana-sync-data-sources-usage.golden index ccb50adbab..f016c90090 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-grafana-sync-data-sources-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-grafana-sync-data-sources-usage.golden @@ -17,3 +17,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-create-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-create-usage.golden index f497eaa1f9..d2cedbe56e 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-create-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-create-usage.golden @@ -21,3 +21,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-delete-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-delete-usage.golden index 12dedaea01..4860b6918c 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-delete-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-delete-usage.golden @@ -19,3 +19,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-list-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-list-usage.golden index f373b932f0..0e7223f5b0 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-list-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-list-usage.golden @@ -19,3 +19,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-reset-password-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-reset-password-usage.golden index fc03ab18fd..d88fb3b79f 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-reset-password-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-grafana-user-reset-password-usage.golden @@ -20,3 +20,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-plan-get-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-plan-get-usage.golden index e51d61b86e..7fb9d0eade 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-plan-get-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-plan-get-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-plan-list-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-plan-list-usage.golden index 7fbcaf406e..077e8b0e3a 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-plan-list-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-plan-list-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-plan-select-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-plan-select-usage.golden index 1ae9ee2984..e40aeddd12 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-plan-select-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-plan-select-usage.golden @@ -19,3 +19,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-product-dashboards-get-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-product-dashboards-get-usage.golden index d18c605b92..8544acd912 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-product-dashboards-get-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-product-dashboards-get-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-product-dashboards-list-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-product-dashboards-list-usage.golden index 821874d69a..2438903d56 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-product-dashboards-list-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-product-dashboards-list-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-test-alert-trigger-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-test-alert-trigger-usage.golden index 181cf4d841..7b50db05f8 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-test-alert-trigger-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-test-alert-trigger-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-token-create-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-token-create-usage.golden index 750c2c40b9..316591c62b 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-token-create-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-token-create-usage.golden @@ -21,3 +21,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-token-delete-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-token-delete-usage.golden index 8d2cb9bd1d..230417b508 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-token-delete-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-token-delete-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-token-get-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-token-get-usage.golden index 9337761346..5ae379d7dd 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-token-get-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-token-get-usage.golden @@ -18,3 +18,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-token-list-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-token-list-usage.golden index 315b7c00ca..93de6018ec 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-token-list-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-token-list-usage.golden @@ -21,3 +21,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/cmd/scw/testdata/test-all-usage-cockpit-usage-overview-get-usage.golden b/cmd/scw/testdata/test-all-usage-cockpit-usage-overview-get-usage.golden index 5fbacae8a2..5ad4f33ee8 100644 --- a/cmd/scw/testdata/test-all-usage-cockpit-usage-overview-get-usage.golden +++ b/cmd/scw/testdata/test-all-usage-cockpit-usage-overview-get-usage.golden @@ -19,3 +19,7 @@ GLOBAL FLAGS: -D, --debug Enable debug mode -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") -p, --profile string The config profile to use + +SEE ALSO: + # Generate a data source configuration snippet + scw cockpit config get diff --git a/docs/commands/cockpit.md b/docs/commands/cockpit.md index f67eda23a0..5ba9bbf1ec 100644 --- a/docs/commands/cockpit.md +++ b/docs/commands/cockpit.md @@ -122,6 +122,7 @@ Generate a ready-to-use configuration snippet for a Cockpit data source. Supported tools: - prometheus: generates a remote_write block for prometheus.yml (metrics data sources only). + - fluent-bit: generates a fluent-bit.conf snippet with a dummy input and an OpenTelemetry output (logs data sources only). Use generate-token=true to create a new Cockpit token and inject it directly in the snippet. The token is created with the minimum required write scope for the data source type. @@ -138,7 +139,7 @@ scw cockpit config get [arg=value ...] | Name | | Description | |------|---|-------------| | data-source-id | Required | ID of the data source to generate the configuration for | -| type | Required
One of: `prometheus` | Configuration template type | +| type | Required
One of: `prometheus`, `fluent-bit` | Configuration template type | | generate-token | | Create a new Cockpit token and inject it in the generated snippet | | token-name | Default: `prometheus-push` | Name of the token to create when generate-token=true | | region | Default: `fr-par`
One of: `fr-par`, `nl-ams`, `pl-waw` | Region to target. If none is passed will use default region from the config | @@ -162,6 +163,16 @@ Generate a Prometheus remote_write snippet with a named token scw cockpit config get 11111111-1111-1111-1111-111111111111 type=prometheus generate-token=true token-name=my-prometheus ``` +Generate a Fluent Bit configuration snippet +``` +scw cockpit config get 11111111-1111-1111-1111-111111111111 type=fluent-bit +``` + +Generate a Fluent Bit configuration snippet with a new token +``` +scw cockpit config get 11111111-1111-1111-1111-111111111111 type=fluent-bit generate-token=true +``` + diff --git a/internal/namespaces/cockpit/v1/custom.go b/internal/namespaces/cockpit/v1/custom.go index 0add7acf17..97b96df031 100644 --- a/internal/namespaces/cockpit/v1/custom.go +++ b/internal/namespaces/cockpit/v1/custom.go @@ -12,6 +12,20 @@ func GetCommands() *core.Commands { cmds.MustFind("cockpit", "token", "get").Override(cockpitTokenGetBuilder) cmds.Add(cockpitConfigRoot()) cmds.Add(cockpitConfigGetCommand()) + addCockpitConfigGetSeeAlso(cmds) return cmds } + +func addCockpitConfigGetSeeAlso(cmds *core.Commands) { + for _, cmd := range cmds.GetAll() { + if cmd.Namespace != "cockpit" || cmd.Run == nil || cmd.Resource == "config" { + continue + } + + cmd.SeeAlsos = append(cmd.SeeAlsos, &core.SeeAlso{ + Command: "scw cockpit config get", + Short: "Generate a data source configuration snippet", + }) + } +} diff --git a/internal/namespaces/cockpit/v1/custom_config_get.go b/internal/namespaces/cockpit/v1/custom_config_get.go index 2a49c327d6..559327fcef 100644 --- a/internal/namespaces/cockpit/v1/custom_config_get.go +++ b/internal/namespaces/cockpit/v1/custom_config_get.go @@ -3,7 +3,9 @@ package cockpit import ( "context" "fmt" + "net/url" "reflect" + "strconv" "strings" "github.com/scaleway/scaleway-cli/v2/core" @@ -15,6 +17,9 @@ type cockpitConfigType string const ( cockpitConfigTypePrometheus cockpitConfigType = "prometheus" + cockpitConfigTypeFluentBit cockpitConfigType = "fluent-bit" + + cockpitLogsOTLPPath = "/otlp/v1/logs" ) // tokenScopeForDataSourceType returns the write scope matching a data source type. @@ -51,6 +56,7 @@ func cockpitConfigGetCommand() *core.Command { Supported tools: - prometheus: generates a remote_write block for prometheus.yml (metrics data sources only). + - fluent-bit: generates a fluent-bit.conf snippet with a dummy input and an OpenTelemetry output (logs data sources only). Use generate-token=true to create a new Cockpit token and inject it directly in the snippet. The token is created with the minimum required write scope for the data source type.`, @@ -63,10 +69,13 @@ The token is created with the minimum required write scope for the data source t Positional: true, }, { - Name: "type", - Short: "Configuration template type", - Required: true, - EnumValues: []string{string(cockpitConfigTypePrometheus)}, + Name: "type", + Short: "Configuration template type", + Required: true, + EnumValues: []string{ + string(cockpitConfigTypePrometheus), + string(cockpitConfigTypeFluentBit), + }, }, { Name: "generate-token", @@ -96,6 +105,14 @@ The token is created with the minimum required write scope for the data source t Short: "Generate a Prometheus remote_write snippet with a named token", ArgsJSON: `{"data_source_id":"11111111-1111-1111-1111-111111111111","type":"prometheus","generate_token":true,"token_name":"my-prometheus"}`, }, + { + Short: "Generate a Fluent Bit configuration snippet", + ArgsJSON: `{"data_source_id":"11111111-1111-1111-1111-111111111111","type":"fluent-bit"}`, + }, + { + Short: "Generate a Fluent Bit configuration snippet with a new token", + ArgsJSON: `{"data_source_id":"11111111-1111-1111-1111-111111111111","type":"fluent-bit","generate_token":true}`, + }, }, SeeAlsos: []*core.SeeAlso{ { @@ -125,21 +142,35 @@ func cockpitConfigGetRun(ctx context.Context, argsI any) (any, error) { return nil, err } - if args.Type == cockpitConfigTypePrometheus && - dataSource.Type != cockpit.DataSourceTypeMetrics { - return nil, &core.CliError{ - Err: fmt.Errorf( - "config type %q requires a metrics data source, got %q", + switch args.Type { + case cockpitConfigTypePrometheus: + if dataSource.Type != cockpit.DataSourceTypeMetrics { + return nil, incompatibleDataSourceTypeError( args.Type, + cockpit.DataSourceTypeMetrics, dataSource.Type, - ), - Hint: "Use `scw cockpit data-source list types.0=metrics` " + - "to find a compatible data source.", + "metrics", + ) } + case cockpitConfigTypeFluentBit: + if dataSource.Type != cockpit.DataSourceTypeLogs { + return nil, incompatibleDataSourceTypeError( + args.Type, + cockpit.DataSourceTypeLogs, + dataSource.Type, + "logs", + ) + } + default: + return nil, fmt.Errorf("unsupported config type %q", args.Type) } var tokenSecretKey *string if args.GenerateToken { + tokenName := args.TokenName + if args.Type == cockpitConfigTypeFluentBit && tokenName == "prometheus-push" { + tokenName = "fluent-bit-push" + } scope, ok := tokenScopeForDataSourceType[dataSource.Type] if !ok { return nil, fmt.Errorf( @@ -151,7 +182,7 @@ func cockpitConfigGetRun(ctx context.Context, argsI any) (any, error) { token, err := api.CreateToken(&cockpit.RegionalAPICreateTokenRequest{ Region: args.Region, ProjectID: dataSource.ProjectID, - Name: args.TokenName, + Name: tokenName, TokenScopes: []cockpit.TokenScope{scope}, }) if err != nil { @@ -164,7 +195,37 @@ func cockpitConfigGetRun(ctx context.Context, argsI any) (any, error) { tokenSecretKey = token.SecretKey } - return RenderPrometheusRemoteWriteConfig(dataSource.URL, tokenSecretKey), nil + switch args.Type { + case cockpitConfigTypePrometheus: + return RenderPrometheusRemoteWriteConfig(dataSource.URL, tokenSecretKey), nil + case cockpitConfigTypeFluentBit: + endpoint, err := ParseCockpitDataSourceEndpoint(dataSource.URL) + if err != nil { + return nil, err + } + + return RenderFluentBitConfig(endpoint, tokenSecretKey), nil + default: + return nil, fmt.Errorf("unsupported config type %q", args.Type) + } +} + +func incompatibleDataSourceTypeError( + configType cockpitConfigType, + required cockpit.DataSourceType, + got cockpit.DataSourceType, + listFilter string, +) *core.CliError { + return &core.CliError{ + Err: fmt.Errorf( + "config type %q requires a %s data source, got %q", + configType, + required, + got, + ), + Hint: "Use `scw cockpit data-source list types.0=" + listFilter + "` " + + "to find a compatible data source.", + } } // RenderPrometheusRemoteWriteConfig renders a Prometheus remote_write YAML snippet for stdout. @@ -201,3 +262,92 @@ func BuildPrometheusRemoteWriteURL(dataSourceURL string) string { return baseURL + "/api/v1/push" } + +// cockpitDataSourceEndpoint holds host and port parsed from a Cockpit data source URL. +type cockpitDataSourceEndpoint struct { + Host string + Port int +} + +// ParseCockpitDataSourceEndpoint parses the host and port from a Cockpit data source URL. +func ParseCockpitDataSourceEndpoint(dataSourceURL string) (cockpitDataSourceEndpoint, error) { + parsedURL, err := url.Parse(dataSourceURL) + if err != nil { + return cockpitDataSourceEndpoint{}, fmt.Errorf("invalid data source URL: %w", err) + } + + host := parsedURL.Hostname() + if host == "" { + return cockpitDataSourceEndpoint{}, fmt.Errorf( + "invalid data source URL %q: missing host", + dataSourceURL, + ) + } + + port := parsedURL.Port() + if port == "" { + if parsedURL.Scheme == "http" { + port = "80" + } else { + port = "443" + } + } + + portNumber, err := strconv.Atoi(port) + if err != nil { + return cockpitDataSourceEndpoint{}, fmt.Errorf( + "invalid data source URL %q: invalid port %q", + dataSourceURL, + port, + ) + } + + return cockpitDataSourceEndpoint{Host: host, Port: portNumber}, nil +} + +// BuildFluentBitLogsURI returns the OpenTelemetry logs URI path for a Cockpit logs data source. +func BuildFluentBitLogsURI(dataSourceURL string) string { + baseURL := strings.TrimRight(dataSourceURL, "/") + if strings.HasSuffix(baseURL, cockpitLogsOTLPPath) { + return cockpitLogsOTLPPath + } + + return cockpitLogsOTLPPath +} + +// RenderFluentBitConfig renders a Fluent Bit configuration snippet for stdout. +func RenderFluentBitConfig( + endpoint cockpitDataSourceEndpoint, + tokenSecretKey *string, +) core.RawResult { + lines := []string{ + "# Snippet of Fluent Bit configuration to add to fluent-bit.conf", + "# Uses a dummy input for testing; replace it with your real log inputs.", + "[SERVICE]", + " Flush 1", + " Log_Level info", + "", + "[INPUT]", + " Name dummy", + " Tag dummy.log", + " Rate 1", + "", + "[OUTPUT]", + " Name opentelemetry", + " Match dummy.log", + " Host " + endpoint.Host, + " Port " + strconv.Itoa(endpoint.Port), + " Logs_uri " + cockpitLogsOTLPPath, + " Log_response_payload True", + " Tls On", + " Tls.verify On", + } + + if tokenSecretKey != nil { + lines = append(lines, " header X-TOKEN "+*tokenSecretKey) + } + + lines = append(lines, "") + + return core.RawResult(strings.Join(lines, "\n")) +} diff --git a/internal/namespaces/cockpit/v1/custom_config_get_test.go b/internal/namespaces/cockpit/v1/custom_config_get_test.go index eb8f8788e8..9bcd7f0d68 100644 --- a/internal/namespaces/cockpit/v1/custom_config_get_test.go +++ b/internal/namespaces/cockpit/v1/custom_config_get_test.go @@ -6,6 +6,7 @@ import ( "github.com/scaleway/scaleway-cli/v2/core" cockpit "github.com/scaleway/scaleway-cli/v2/internal/namespaces/cockpit/v1" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func Test_BuildPrometheusRemoteWriteURL(t *testing.T) { @@ -27,6 +28,98 @@ func Test_BuildPrometheusRemoteWriteURL(t *testing.T) { }) } +func Test_ParseCockpitDataSourceEndpoint(t *testing.T) { + t.Run("https default port", func(t *testing.T) { + const host = "000avb0d-34ae-66hh-643b-f9e0n3k17773.logs.cockpit.fr-par.scw.cloud" + + endpoint, err := cockpit.ParseCockpitDataSourceEndpoint("https://" + host) + require.NoError(t, err) + assert.Equal(t, host, endpoint.Host) + assert.Equal(t, 443, endpoint.Port) + }) + + t.Run("explicit port", func(t *testing.T) { + endpoint, err := cockpit.ParseCockpitDataSourceEndpoint( + "https://example.logs.cockpit.fr-par.scw.cloud:8443", + ) + require.NoError(t, err) + assert.Equal(t, "example.logs.cockpit.fr-par.scw.cloud", endpoint.Host) + assert.Equal(t, 8443, endpoint.Port) + }) +} + +func Test_BuildFluentBitLogsURI(t *testing.T) { + assert.Equal(t, "/otlp/v1/logs", cockpit.BuildFluentBitLogsURI( + "https://example.logs.cockpit.fr-par.scw.cloud", + )) + assert.Equal(t, "/otlp/v1/logs", cockpit.BuildFluentBitLogsURI( + "https://example.logs.cockpit.fr-par.scw.cloud/otlp/v1/logs", + )) +} + +func Test_RenderFluentBitConfig(t *testing.T) { + endpoint, err := cockpit.ParseCockpitDataSourceEndpoint( + "https://example.logs.cockpit.fr-par.scw.cloud", + ) + require.NoError(t, err) + + t.Run("without token", func(t *testing.T) { + got := cockpit.RenderFluentBitConfig(endpoint, nil) + want := core.RawResult( + "# Snippet of Fluent Bit configuration to add to fluent-bit.conf\n" + + "# Uses a dummy input for testing; replace it with your real log inputs.\n" + + "[SERVICE]\n" + + " Flush 1\n" + + " Log_Level info\n" + + "\n" + + "[INPUT]\n" + + " Name dummy\n" + + " Tag dummy.log\n" + + " Rate 1\n" + + "\n" + + "[OUTPUT]\n" + + " Name opentelemetry\n" + + " Match dummy.log\n" + + " Host example.logs.cockpit.fr-par.scw.cloud\n" + + " Port 443\n" + + " Logs_uri /otlp/v1/logs\n" + + " Log_response_payload True\n" + + " Tls On\n" + + " Tls.verify On\n", + ) + assert.Equal(t, want, got) + }) + + t.Run("with token", func(t *testing.T) { + token := "my-secret-token" + got := cockpit.RenderFluentBitConfig(endpoint, &token) + want := core.RawResult( + "# Snippet of Fluent Bit configuration to add to fluent-bit.conf\n" + + "# Uses a dummy input for testing; replace it with your real log inputs.\n" + + "[SERVICE]\n" + + " Flush 1\n" + + " Log_Level info\n" + + "\n" + + "[INPUT]\n" + + " Name dummy\n" + + " Tag dummy.log\n" + + " Rate 1\n" + + "\n" + + "[OUTPUT]\n" + + " Name opentelemetry\n" + + " Match dummy.log\n" + + " Host example.logs.cockpit.fr-par.scw.cloud\n" + + " Port 443\n" + + " Logs_uri /otlp/v1/logs\n" + + " Log_response_payload True\n" + + " Tls On\n" + + " Tls.verify On\n" + + " header X-TOKEN my-secret-token\n", + ) + assert.Equal(t, want, got) + }) +} + func Test_RenderPrometheusRemoteWriteConfig(t *testing.T) { const baseURL = "https://example.metrics.fr-par.scw.cloud"