-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add openstack config converter (#5208)
* add openstack config converter * change tls_config from attr to block * remove newline is diags
- Loading branch information
Showing
12 changed files
with
255 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package prometheusconvert | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/grafana/agent/component/discovery" | ||
"github.com/grafana/agent/component/discovery/openstack" | ||
"github.com/grafana/agent/converter/diag" | ||
"github.com/grafana/agent/converter/internal/common" | ||
"github.com/grafana/river/rivertypes" | ||
prom_openstack "github.com/prometheus/prometheus/discovery/openstack" | ||
) | ||
|
||
func appendDiscoveryOpenstack(pb *prometheusBlocks, label string, sdConfig *prom_openstack.SDConfig) discovery.Exports { | ||
discoveryOpenstackArgs := toDiscoveryOpenstack(sdConfig) | ||
name := []string{"discovery", "openstack"} | ||
block := common.NewBlockWithOverride(name, label, discoveryOpenstackArgs) | ||
pb.discoveryBlocks = append(pb.discoveryBlocks, newPrometheusBlock(block, name, label, "", "")) | ||
return NewDiscoveryExports("discovery.openstack." + label + ".targets") | ||
} | ||
|
||
func validateDiscoveryOpenstack(sdConfig *prom_openstack.SDConfig) diag.Diagnostics { | ||
return nil | ||
} | ||
|
||
func toDiscoveryOpenstack(sdConfig *prom_openstack.SDConfig) *openstack.Arguments { | ||
if sdConfig == nil { | ||
return nil | ||
} | ||
|
||
return &openstack.Arguments{ | ||
IdentityEndpoint: sdConfig.IdentityEndpoint, | ||
Username: sdConfig.Username, | ||
UserID: sdConfig.UserID, | ||
Password: rivertypes.Secret(sdConfig.Password), | ||
ProjectName: sdConfig.ProjectName, | ||
ProjectID: sdConfig.ProjectID, | ||
DomainName: sdConfig.DomainName, | ||
DomainID: sdConfig.DomainID, | ||
ApplicationCredentialName: sdConfig.ApplicationCredentialName, | ||
ApplicationCredentialID: sdConfig.ApplicationCredentialID, | ||
ApplicationCredentialSecret: rivertypes.Secret(sdConfig.ApplicationCredentialSecret), | ||
Role: string(sdConfig.Role), | ||
Region: sdConfig.Region, | ||
RefreshInterval: time.Duration(sdConfig.RefreshInterval), | ||
Port: sdConfig.Port, | ||
AllTenants: sdConfig.AllTenants, | ||
TLSConfig: *ToTLSConfig(&sdConfig.TLSConfig), | ||
Availability: sdConfig.Availability, | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
converter/internal/prometheusconvert/testdata/openstack.river
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,60 @@ | ||
discovery.openstack "prometheus1" { | ||
identity_endpoint = "identity_endpoint" | ||
username = "username" | ||
userid = "userid" | ||
password = "password" | ||
project_name = "project_name" | ||
project_id = "project_id" | ||
domain_name = "domain_name" | ||
domain_id = "domain_id" | ||
application_credential_name = "application_credential_name" | ||
application_credential_id = "application_credential_id" | ||
application_credential_secret = "application_credential_secret" | ||
role = "instance" | ||
region = "region" | ||
refresh_interval = "20s" | ||
port = 81 | ||
all_tenants = true | ||
|
||
tls_config { | ||
ca_pem = "ca" | ||
cert_pem = "cert" | ||
key_pem = "key" | ||
server_name = "example.local" | ||
insecure_skip_verify = true | ||
} | ||
availability = "internal" | ||
} | ||
|
||
discovery.openstack "prometheus2" { | ||
role = "hypervisor" | ||
region = "region2" | ||
} | ||
|
||
prometheus.scrape "prometheus1" { | ||
targets = concat( | ||
discovery.openstack.prometheus1.targets, | ||
[{ | ||
__address__ = "localhost:9090", | ||
}], | ||
) | ||
forward_to = [prometheus.remote_write.default.receiver] | ||
job_name = "prometheus1" | ||
} | ||
|
||
prometheus.scrape "prometheus2" { | ||
targets = discovery.openstack.prometheus2.targets | ||
forward_to = [prometheus.remote_write.default.receiver] | ||
job_name = "prometheus2" | ||
} | ||
|
||
prometheus.remote_write "default" { | ||
endpoint { | ||
name = "remote1" | ||
url = "http://remote-write-url1" | ||
|
||
queue_config { } | ||
|
||
metadata_config { } | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
converter/internal/prometheusconvert/testdata/openstack.yaml
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,37 @@ | ||
scrape_configs: | ||
- job_name: "prometheus1" | ||
static_configs: | ||
- targets: ["localhost:9090"] | ||
openstack_sd_configs: | ||
- identity_endpoint: "identity_endpoint" | ||
username: "username" | ||
userid: "userid" | ||
password: "password" | ||
project_name: "project_name" | ||
project_id: "project_id" | ||
domain_name: "domain_name" | ||
domain_id: "domain_id" | ||
application_credential_name: "application_credential_name" | ||
application_credential_id: "application_credential_id" | ||
application_credential_secret: "application_credential_secret" | ||
role: "instance" | ||
region: "region" | ||
port: 81 | ||
all_tenants: true | ||
availability: "internal" | ||
refresh_interval: 20s | ||
tls_config: | ||
key: "key" | ||
cert: "cert" | ||
ca: "ca" | ||
server_name: example.local | ||
insecure_skip_verify: true | ||
|
||
- job_name: "prometheus2" | ||
openstack_sd_configs: | ||
- role: "hypervisor" | ||
region: "region2" | ||
|
||
remote_write: | ||
- name: "remote1" | ||
url: "http://remote-write-url1" |
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
47 changes: 47 additions & 0 deletions
47
converter/internal/promtailconvert/testdata/openstack.river
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,47 @@ | ||
discovery.openstack "prometheus1" { | ||
identity_endpoint = "identity_endpoint" | ||
username = "username" | ||
userid = "userid" | ||
password = "password" | ||
project_name = "project_name" | ||
project_id = "project_id" | ||
domain_name = "domain_name" | ||
domain_id = "domain_id" | ||
application_credential_name = "application_credential_name" | ||
application_credential_id = "application_credential_id" | ||
application_credential_secret = "application_credential_secret" | ||
role = "instance" | ||
region = "region" | ||
refresh_interval = "20s" | ||
port = 81 | ||
all_tenants = true | ||
|
||
tls_config { | ||
ca_pem = "ca" | ||
cert_pem = "cert" | ||
key_pem = "key" | ||
server_name = "example.local" | ||
insecure_skip_verify = true | ||
} | ||
availability = "internal" | ||
} | ||
|
||
discovery.openstack "prometheus1_2" { | ||
role = "hypervisor" | ||
region = "region2" | ||
} | ||
|
||
local.file_match "prometheus1" { | ||
path_targets = concat( | ||
discovery.openstack.prometheus1.targets, | ||
discovery.openstack.prometheus1_2.targets, | ||
[{ | ||
__address__ = "localhost:9090", | ||
}], | ||
) | ||
} | ||
|
||
loki.source.file "prometheus1" { | ||
targets = local.file_match.prometheus1.targets | ||
forward_to = [] | ||
} |
32 changes: 32 additions & 0 deletions
32
converter/internal/promtailconvert/testdata/openstack.yaml
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,32 @@ | ||
scrape_configs: | ||
- job_name: "prometheus1" | ||
static_configs: | ||
- targets: ["localhost:9090"] | ||
openstack_sd_configs: | ||
- identity_endpoint: "identity_endpoint" | ||
username: "username" | ||
userid: "userid" | ||
password: "password" | ||
project_name: "project_name" | ||
project_id: "project_id" | ||
domain_name: "domain_name" | ||
domain_id: "domain_id" | ||
application_credential_name: "application_credential_name" | ||
application_credential_id: "application_credential_id" | ||
application_credential_secret: "application_credential_secret" | ||
role: "instance" | ||
region: "region" | ||
port: 81 | ||
all_tenants: true | ||
availability: "internal" | ||
refresh_interval: 20s | ||
tls_config: | ||
key: "key" | ||
cert: "cert" | ||
ca: "ca" | ||
server_name: example.local | ||
insecure_skip_verify: true | ||
- role: "hypervisor" | ||
region: "region2" | ||
tracing: {enabled: false} | ||
server: {register_instrumentation: false} |
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