Skip to content

Commit

Permalink
Merge pull request k0smotron#597 from makhov/monitoring-stack-fix-for…
Browse files Browse the repository at this point in the history
…-external-etcd

Fixes scrape config for the external etcd
  • Loading branch information
makhov authored May 29, 2024
2 parents 94d6845 + 859c9fa commit 29b3bed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ func init() {

func (r *ClusterReconciler) generateMonitoringCM(kmc *km.Cluster) (v1.ConfigMap, error) {
var entrypointBuf bytes.Buffer
err := prometheusConfigTmpl.Execute(&entrypointBuf, kmc)
err := prometheusConfigTmpl.Execute(&entrypointBuf, struct {
Kmc *km.Cluster
EtcdSvcName string
}{
Kmc: kmc,
EtcdSvcName: kmc.GetEtcdServiceName(),
})
if err != nil {
return v1.ConfigMap{}, err
}
Expand Down Expand Up @@ -87,29 +93,29 @@ scrape_configs:
cert_file: /var/lib/k0s/pki/admin.crt
key_file: /var/lib/k0s/pki/admin.key
static_configs:
- targets: ["localhost:{{ .Spec.Service.APIPort }}"]
- targets: ["localhost:{{ .Kmc.Spec.Service.APIPort }}"]
labels:
component: kube-apiserver
k0smotron_cluster: "{{ .Name }}"
k0smotron_cluster: "{{ .Kmc.Name }}"
- targets: ["localhost:10259"]
labels:
component: kube-scheduler
k0smotron_cluster: "{{ .Name }}"
k0smotron_cluster: "{{ .Kmc.Name }}"
- targets: ["localhost:10257"]
labels:
component: kube-controller-manager
k0smotron_cluster: "{{ .Name }}"
k0smotron_cluster: "{{ .Kmc.Name }}"
- job_name: "k0smotron_etcd_metrics"
scheme: https
tls_config:
insecure_skip_verify: true
cert_file: /var/lib/k0s/pki/etcd/ca.crt
key_file: /var/lib/k0s/pki/etcd/ca.key
cert_file: /var/lib/k0s/pki/etcd-ca.crt
key_file: /var/lib/k0s/pki/etcd-ca.key
static_configs:
- targets: ["localhost:2379"]
- targets: ["{{ .EtcdSvcName }}:2379"]
labels:
component: etcd
k0smotron_cluster: "{{ .Name }}"
k0smotron_cluster: "{{ .Kmc.Name }}"
`

const nginxConf = `
Expand Down
4 changes: 2 additions & 2 deletions inttest/monitoring/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ func (s *MonitoringSuite) TestK0sGetsUp() {
b, err := kc.RESTClient().
Get().
AbsPath("/api/v1/namespaces/default/services/prometheus-server:http/proxy/api/v1/query").
Param("query", "workqueue_work_duration_seconds_count").
Param("query", "process_open_fds").
DoRaw(s.Context())
if err != nil {
return true, err
}

out := string(b)

return strings.Contains(out, `"k0smotron_cluster":"kmc-test"`), nil
return strings.Contains(out, `k0smotron_etcd_metrics`), nil
})
s.Require().NoError(err)
}
Expand Down

0 comments on commit 29b3bed

Please sign in to comment.