add parameter url to grafana

This commit is contained in:
ansgarz 2022-05-18 21:49:28 +02:00
parent eb514fb8aa
commit c9b1643287
7 changed files with 12 additions and 9 deletions

View file

@ -5,5 +5,5 @@ import org.domaindrivenarchitecture.provs.server.infrastructure.provisionGrafana
fun Prov.provisionGrafanaAgent(configResolved: GrafanaAgentConfigResolved) = fun Prov.provisionGrafanaAgent(configResolved: GrafanaAgentConfigResolved) =
provisionGrafanaAgentForK8s(configResolved.user, configResolved.password, configResolved.cluster) provisionGrafanaAgentForK8s(configResolved.user, configResolved.password, configResolved.cluster, configResolved.url)

View file

@ -8,7 +8,8 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.SecretSupplier
data class GrafanaAgentConfig( data class GrafanaAgentConfig(
val user: String, val user: String,
val password: SecretSupplier, val password: SecretSupplier,
val cluster: String val cluster: String,
val url: String
) { ) {
fun resolveSecret(): GrafanaAgentConfigResolved = GrafanaAgentConfigResolved(this) fun resolveSecret(): GrafanaAgentConfigResolved = GrafanaAgentConfigResolved(this)
} }
@ -17,6 +18,7 @@ data class GrafanaAgentConfigResolved(val configUnresolved: GrafanaAgentConfig)
val user: String = configUnresolved.user val user: String = configUnresolved.user
val password: Secret = configUnresolved.password.secret() val password: Secret = configUnresolved.password.secret()
val cluster: String = configUnresolved.cluster val cluster: String = configUnresolved.cluster
val url: String = configUnresolved.url
} }
@Serializable @Serializable

View file

@ -11,7 +11,7 @@ import java.io.File
private const val grafanaResourceDir = "org/domaindrivenarchitecture/provs/server/infrastructure/grafana/" private const val grafanaResourceDir = "org/domaindrivenarchitecture/provs/server/infrastructure/grafana/"
fun Prov.provisionGrafanaAgentForK8s(user: String, password: Secret, clusterName: String) = task { fun Prov.provisionGrafanaAgentForK8s(user: String, password: Secret, clusterName: String, url: String) = task {
val namespace = "monitoring" val namespace = "monitoring"
// Create namespace if not yet existing // Create namespace if not yet existing
@ -35,6 +35,7 @@ fun Prov.provisionGrafanaAgentForK8s(user: String, password: Secret, clusterName
"USERNAME" to user, "USERNAME" to user,
"APIKEY" to password.plain(), "APIKEY" to password.plain(),
"CLUSTERNAME" to clusterName, "CLUSTERNAME" to clusterName,
"URL" to url,
) )
) )
cmd("export NAMESPACE=$namespace && kubectl apply -n \$NAMESPACE -f grafana-agent-config-map.yaml", k3sManualManifestsDir) cmd("export NAMESPACE=$namespace && kubectl apply -n \$NAMESPACE -f grafana-agent-config-map.yaml", k3sManualManifestsDir)

View file

@ -17,12 +17,11 @@ private const val DEFAULT_CONFIG_FILE = "server-config.yaml"
fun findK8sGrafanaConfig(fileName: ConfigFileName? = null): GrafanaAgentConfig? { fun findK8sGrafanaConfig(fileName: ConfigFileName? = null): GrafanaAgentConfig? {
val filePath = fileName?.fileName ?: DEFAULT_CONFIG_FILE val filePath = fileName?.fileName ?: DEFAULT_CONFIG_FILE
// create a default config
return if (File(filePath).exists()) { return if (File(filePath).exists()) {
try { try {
readFromFile(filePath).yamlToType<GrafanaAgentConfigHolder>().grafana readFromFile(filePath).yamlToType<GrafanaAgentConfigHolder>().grafana
} catch (e: MissingRequiredPropertyException) { } catch (e: MissingRequiredPropertyException) {
null if (e.message.contains("Property 'grafana'")) null else throw e
} }
} else { } else {
null null

View file

@ -16,7 +16,7 @@ data:
configs: configs:
- name: integrations - name: integrations
remote_write: remote_write:
- url: https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push - url: $URL
basic_auth: basic_auth:
username: $USERNAME username: $USERNAME
password: $APIKEY password: $APIKEY
@ -90,7 +90,7 @@ data:
integrations: integrations:
prometheus_remote_write: prometheus_remote_write:
- url: https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push - url: $URL
basic_auth: basic_auth:
username: $USERNAME username: $USERNAME
password: $APIKEY password: $APIKEY

View file

@ -19,7 +19,8 @@ internal class GrafanaAgentRepositoryKtTest {
GrafanaAgentConfig( GrafanaAgentConfig(
user = "654321", user = "654321",
password = SecretSupplier(SecretSourceType.GOPASS, "path/to/key"), password = SecretSupplier(SecretSourceType.GOPASS, "path/to/key"),
cluster = "myclustername" cluster = "myclustername",
url = "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push"
), config ), config
) )
} }

View file

@ -15,4 +15,4 @@ grafana:
source: "GOPASS" # PLAIN, GOPASS or PROMPT source: "GOPASS" # PLAIN, GOPASS or PROMPT
parameter: "path/to/key" # password of the user or api key parameter: "path/to/key" # password of the user or api key
cluster: "myclustername" # the cluster name of your choice cluster: "myclustername" # the cluster name of your choice
url: "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push"