add parameter url to grafana
This commit is contained in:
parent
eb514fb8aa
commit
c9b1643287
7 changed files with 12 additions and 9 deletions
|
@ -5,5 +5,5 @@ import org.domaindrivenarchitecture.provs.server.infrastructure.provisionGrafana
|
|||
|
||||
|
||||
fun Prov.provisionGrafanaAgent(configResolved: GrafanaAgentConfigResolved) =
|
||||
provisionGrafanaAgentForK8s(configResolved.user, configResolved.password, configResolved.cluster)
|
||||
provisionGrafanaAgentForK8s(configResolved.user, configResolved.password, configResolved.cluster, configResolved.url)
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.SecretSupplier
|
|||
data class GrafanaAgentConfig(
|
||||
val user: String,
|
||||
val password: SecretSupplier,
|
||||
val cluster: String
|
||||
val cluster: String,
|
||||
val url: String
|
||||
) {
|
||||
fun resolveSecret(): GrafanaAgentConfigResolved = GrafanaAgentConfigResolved(this)
|
||||
}
|
||||
|
@ -17,6 +18,7 @@ data class GrafanaAgentConfigResolved(val configUnresolved: GrafanaAgentConfig)
|
|||
val user: String = configUnresolved.user
|
||||
val password: Secret = configUnresolved.password.secret()
|
||||
val cluster: String = configUnresolved.cluster
|
||||
val url: String = configUnresolved.url
|
||||
}
|
||||
|
||||
@Serializable
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.io.File
|
|||
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"
|
||||
|
||||
// Create namespace if not yet existing
|
||||
|
@ -35,6 +35,7 @@ fun Prov.provisionGrafanaAgentForK8s(user: String, password: Secret, clusterName
|
|||
"USERNAME" to user,
|
||||
"APIKEY" to password.plain(),
|
||||
"CLUSTERNAME" to clusterName,
|
||||
"URL" to url,
|
||||
)
|
||||
)
|
||||
cmd("export NAMESPACE=$namespace && kubectl apply -n \$NAMESPACE -f grafana-agent-config-map.yaml", k3sManualManifestsDir)
|
||||
|
|
|
@ -17,12 +17,11 @@ private const val DEFAULT_CONFIG_FILE = "server-config.yaml"
|
|||
fun findK8sGrafanaConfig(fileName: ConfigFileName? = null): GrafanaAgentConfig? {
|
||||
val filePath = fileName?.fileName ?: DEFAULT_CONFIG_FILE
|
||||
|
||||
// create a default config
|
||||
return if (File(filePath).exists()) {
|
||||
try {
|
||||
readFromFile(filePath).yamlToType<GrafanaAgentConfigHolder>().grafana
|
||||
} catch (e: MissingRequiredPropertyException) {
|
||||
null
|
||||
if (e.message.contains("Property 'grafana'")) null else throw e
|
||||
}
|
||||
} else {
|
||||
null
|
||||
|
|
|
@ -16,7 +16,7 @@ data:
|
|||
configs:
|
||||
- name: integrations
|
||||
remote_write:
|
||||
- url: https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push
|
||||
- url: $URL
|
||||
basic_auth:
|
||||
username: $USERNAME
|
||||
password: $APIKEY
|
||||
|
@ -90,7 +90,7 @@ data:
|
|||
|
||||
integrations:
|
||||
prometheus_remote_write:
|
||||
- url: https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push
|
||||
- url: $URL
|
||||
basic_auth:
|
||||
username: $USERNAME
|
||||
password: $APIKEY
|
||||
|
|
|
@ -19,7 +19,8 @@ internal class GrafanaAgentRepositoryKtTest {
|
|||
GrafanaAgentConfig(
|
||||
user = "654321",
|
||||
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
|
||||
)
|
||||
}
|
||||
|
|
|
@ -15,4 +15,4 @@ grafana:
|
|||
source: "GOPASS" # PLAIN, GOPASS or PROMPT
|
||||
parameter: "path/to/key" # password of the user or api key
|
||||
cluster: "myclustername" # the cluster name of your choice
|
||||
|
||||
url: "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push"
|
Loading…
Reference in a new issue