Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support resource state metrics like kube-state-metrics #539

Merged
merged 6 commits into from
Jul 17, 2023

Conversation

Iceber
Copy link
Member

@Iceber Iceber commented Jul 13, 2023

What type of PR is this?

What this PR does / why we need it:
The cluster synchro has the same source data as kube-state-metrics available to it at sync time,
so clusterpedia can easily support functionality similar to kube-state-metrics

This pr allows the ClusterSynchro Manager to expose the same resource state metrics for multiple clusters as kube-state-metrics, which of course have the cluster name included in the label.

# HELP kube_deployment_created [STABLE] Unix creation timestamp
# TYPE kube_deployment_created gauge
kube_deployment_created{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-apiserver"} 1.676557618e+09
kube_deployment_created{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-clustersynchro-manager"} 1.676557618e+09
kube_deployment_created{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-controller-manager"} 1.676557618e+09
kube_deployment_created{cluster="test-14",namespace="kube-system",deployment="coredns"} 1.673603507e+09
# HELP kube_deployment_status_replicas [STABLE] The number of replicas per deployment.
# TYPE kube_deployment_status_replicas gauge
kube_deployment_status_replicas{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-apiserver"} 1
kube_deployment_status_replicas{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-clustersynchro-manager"} 0
kube_deployment_status_replicas{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-controller-manager"} 1
kube_deployment_status_replicas{cluster="test-14",namespace="kube-system",deployment="coredns"} 2
# HELP kube_deployment_status_replicas_ready [STABLE] The number of ready replicas per deployment.
# TYPE kube_deployment_status_replicas_ready gauge
kube_deployment_status_replicas_ready{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-apiserver"} 1
kube_deployment_status_replicas_ready{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-clustersynchro-manager"} 0
kube_deployment_status_replicas_ready{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-controller-manager"} 1
kube_deployment_status_replicas_ready{cluster="test-14",namespace="kube-system",deployment="coredns"} 2
# HELP kube_deployment_status_replicas_available [STABLE] The number of available replicas per deployment.
# TYPE kube_deployment_status_replicas_available gauge
kube_deployment_status_replicas_available{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-apiserver"} 1
kube_deployment_status_replicas_available{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-clustersynchro-manager"} 0
kube_deployment_status_replicas_available{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-controller-manager"} 1
kube_deployment_status_replicas_available{cluster="test-14",namespace="kube-system",deployment="coredns"} 2
# HELP kube_deployment_status_replicas_unavailable [STABLE] The number of unavailable replicas per deployment.
# TYPE kube_deployment_status_replicas_unavailable gauge
kube_deployment_status_replicas_unavailable{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-apiserver"} 0
kube_deployment_status_replicas_unavailable{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-clustersynchro-manager"} 0
kube_deployment_status_replicas_unavailable{cluster="test-14",namespace="clusterpedia-system",deployment="clusterpedia-controller-manager"} 0
kube_deployment_status_replicas_unavailable{cluster="test-14",namespace="kube-system",deployment="coredns"} 0
# HELP kube_deployment_status_replicas_updated [STABLE] The number of updated replicas per deployment.

The following flags have been added to the clustersynchro-manager command.

$ ./bin/clustersynchro-manager -h
Metrics server flags:

      --metrics-disable-gzip-encoding
                Gzip responses when requested by clients via 'Accept-Encoding: gzip' header.
      --metrics-host string
                Host to expose clustersynchro manager metrics on. (default "::")
      --metrics-port int
                Port to expose clustersynchro manager metrics on. (default 8081)
      --metrics-tls-config string
                Path to the TLS configuration file of metrics

Kube state metrics flags:

      --enable-kube-state-metrics
                Enabled kube state metrics
      --kube-state-metrics-host string
                Host to expose kube state metrics on. (default "::")
      --kube-state-metrics-metric-allowlist string
                Comma-separated list of metrics to be exposed. This list comprises of exact metric names
                and/or regex patterns. The allowlist and denylist are mutually exclusive.
      --kube-state-metrics-metric-denylist string
                Comma-separated list of metrics not to be enabled. This list comprises of exact metric
                names and/or regex patterns. The allowlist and denylist are mutually exclusive.
      --kube-state-metrics-metric-opt-in-list string
                Comma-separated list of metrics which are opt-in and not enabled by default. This is in
                addition to the metric allow- and denylists
      --kube-state-metrics-namespaces string
                Comma-separated list of namespaces to be enabled. Defaults to ""
      --kube-state-metrics-namespaces-denylist string
                Comma-separated list of namespaces not to be enabled. If namespaces and
                namespaces-denylist are both set, only namespaces that are excluded in namespaces-denylist
                will be used.
      --kube-state-metrics-port int
                Port to expose kube state metrics on. (default 8080)
      --kube-state-metrics-resources string
                Comma-separated list of Resources to be enabled. Supported resources:
                "cronjobs,daemonsets,deployments,ingressclasses,ingresses,jobs,namespaces,nodes,pods,replicasets,secrets,services,statefulsets" (default "deployments,pods,services")

Quick

  1. deploy crds
kubectl apply -f ./deploy/crds
  1. local sqlite storage config
type: sqlite
dsn: file:test.db
  1. run clustersynchro manager
$  ./bin/clustersynchro-manager --kubeconfig $HOME/.kube/config --storage-config=./sqlite.yaml --enable-kube-state-metrics
  1. curl kube-state-metrics
curl 127.0.0.1:8080/metrics

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


@clusterpedia-bot
Copy link

Hi @Iceber,
Thanks for your pull request!
If the PR is ready, use the /auto-cc command to assign Reviewer to Review.
We will review it shortly.

Details

Instructions for interacting with me using comments are available here.
If you have questions or suggestions related to my behavior, please file an issue against the gh-ci-bot repository.

Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
@Iceber Iceber force-pushed the kube-state-metrics branch 4 times, most recently from f4bacc4 to 45c9108 Compare July 14, 2023 08:48
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
@Iceber Iceber changed the title [WIP] support resource state metrics like kube-state-metrics support resource state metrics like kube-state-metrics Jul 17, 2023
@Iceber Iceber merged commit 7b7f4be into clusterpedia-io:main Jul 17, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants