diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 35fde4e..bda89c1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -2,9 +2,6 @@ name: e2e on: push: - branches: - - main - - master jobs: e2e: diff --git a/Makefile b/Makefile index 9ad17fb..b98ed85 100644 --- a/Makefile +++ b/Makefile @@ -49,19 +49,19 @@ release-docker: release-helm: cd chart - sed -i "s/tag.*/tag: ${VERSION}/g" values.yaml - sed -i "s/version.*/version: ${VERSION}/g" Chart.yaml - sed -i "s/appVersion.*/appVersion: ${VERSION}/g" Chart.yaml + sed -i "s/tag:.*/tag: ${VERSION}/g" values.yaml + sed -i "s/version:.*/version: ${VERSION}/g" Chart.yaml + sed -i "s/appVersion:.*/appVersion: ${VERSION}/g" Chart.yaml helm package . helm repo index --merge index.yaml . sed -i "s!k8s-ephemeral-storage-metrics-${VERSION}.tgz!https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics/releases/download/${VERSION}/k8s-ephemeral-storage-metrics-${VERSION}.tgz!g" index.yaml cd .. release: github_login release-docker release-helm helm-docs - # ex. make VERSION=1.2.1 release + # ex. make VERSION=1.3.0 release release-github: github_login - # ex. make VERSION=1.2.1 release-github + # ex. make VERSION=1.3.0 release-github gh release create ${VERSION} --generate-notes gh release upload ${VERSION} "chart/k8s-ephemeral-storage-metrics-${VERSION}.tgz" rm chart/k8s-ephemeral-storage-metrics-*.tgz diff --git a/README.md b/README.md index 8f75737..1a7d26e 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,18 @@ helm upgrade --install my-deployment k8s-ephemeral-storage-metrics/k8s-ephemeral |-----|------|---------|-------------| | deploy_type | string | `"Deployment"` | Set as Deployment for single controller to query all nodes or Daemonset | | dev.enabled | bool | `false` | | -| extra.adjusted_polling_rate | bool | `false` | Create the ephemeral_storage_adjusted_polling_rate metrics to report Adjusted Poll Rate in milliseconds. Typically used for testing. | | image.imagePullPolicy | string | `"IfNotPresent"` | | | image.repository | string | `"ghcr.io/jmcgrath207/k8s-ephemeral-storage-metrics"` | | -| image.tag | string | `"1.2.1"` | | +| image.tag | string | `"1.3.0"` | | | interval | int | `15` | Polling node rate for exporter | | log_level | string | `"info"` | | -| max_node_concurrency | int | `10` | Max amount of concurrent query requests at a time. | +| max_node_concurrency | int | `10` | Max number of concurrent query requests to the kubernetes API. | +| metrics | object | `{"adjusted_polling_rate":false,"ephemeral_storage_node_available":true,"ephemeral_storage_node_capacity":true,"ephemeral_storage_node_percentage":true,"ephemeral_storage_pod_usage":true}` | Set metrics you want to enable | +| metrics.adjusted_polling_rate | bool | `false` | Create the ephemeral_storage_adjusted_polling_rate metrics to report Adjusted Poll Rate in milliseconds. Typically used for testing. | +| metrics.ephemeral_storage_node_available | bool | `true` | Available ephemeral storage for a node | +| metrics.ephemeral_storage_node_capacity | bool | `true` | Capacity of ephemeral storage for a node | +| metrics.ephemeral_storage_node_percentage | bool | `true` | Percentage of ephemeral storage used on a node | +| metrics.ephemeral_storage_pod_usage | bool | `true` | Current ephemeral byte usage of pod | | nodeSelector | object | `{}` | | | podAnnotations | object | `{}` | | | prometheus.enable | bool | `true` | | diff --git a/chart/Chart.yaml b/chart/Chart.yaml index 63e250e..6f7f792 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: k8s-ephemeral-storage-metrics -version: 1.2.1 -appVersion: 1.2.1 +version: 1.3.0 +appVersion: 1.3.0 kubeVersion: ">=1.21.0-0" description: Ephemeral storage metrics for prometheus operator. home: https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics diff --git a/chart/README.md b/chart/README.md index 35c0267..5f446b2 100644 --- a/chart/README.md +++ b/chart/README.md @@ -12,13 +12,18 @@ helm upgrade --install my-deployment k8s-ephemeral-storage-metrics/k8s-ephemeral |-----|------|---------|-------------| | deploy_type | string | `"Deployment"` | Set as Deployment for single controller to query all nodes or Daemonset | | dev.enabled | bool | `false` | | -| extra.adjusted_polling_rate | bool | `false` | Create the ephemeral_storage_adjusted_polling_rate metrics to report Adjusted Poll Rate in milliseconds. Typically used for testing. | | image.imagePullPolicy | string | `"IfNotPresent"` | | | image.repository | string | `"ghcr.io/jmcgrath207/k8s-ephemeral-storage-metrics"` | | -| image.tag | string | `"1.2.1"` | | +| image.tag | string | `"1.3.0"` | | | interval | int | `15` | Polling node rate for exporter | | log_level | string | `"info"` | | -| max_node_concurrency | int | `10` | Max amount of concurrent query requests at a time. | +| max_node_concurrency | int | `10` | Max number of concurrent query requests to the kubernetes API. | +| metrics | object | `{"adjusted_polling_rate":false,"ephemeral_storage_node_available":true,"ephemeral_storage_node_capacity":true,"ephemeral_storage_node_percentage":true,"ephemeral_storage_pod_usage":true}` | Set metrics you want to enable | +| metrics.adjusted_polling_rate | bool | `false` | Create the ephemeral_storage_adjusted_polling_rate metrics to report Adjusted Poll Rate in milliseconds. Typically used for testing. | +| metrics.ephemeral_storage_node_available | bool | `true` | Available ephemeral storage for a node | +| metrics.ephemeral_storage_node_capacity | bool | `true` | Capacity of ephemeral storage for a node | +| metrics.ephemeral_storage_node_percentage | bool | `true` | Percentage of ephemeral storage used on a node | +| metrics.ephemeral_storage_pod_usage | bool | `true` | Current ephemeral byte usage of pod | | nodeSelector | object | `{}` | | | podAnnotations | object | `{}` | | | prometheus.enable | bool | `true` | | diff --git a/chart/index.yaml b/chart/index.yaml index f7e496a..224cdfa 100644 --- a/chart/index.yaml +++ b/chart/index.yaml @@ -1,6 +1,28 @@ apiVersion: v1 entries: k8s-ephemeral-storage-metrics: + - annotations: + artifacthub.io/license: MIT + artifacthub.io/links: | + - name: Documentation + url: https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics + artifacthub.io/prerelease: "false" + apiVersion: v2 + appVersion: 1.3.0 + created: "2023-11-26T22:34:31.469506023-06:00" + description: Ephemeral storage metrics for prometheus operator. + digest: 907280778c7dfb692248f3585ce53b848d4e4b9d2db6e13e4752c6033604f77a + home: https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics + keywords: + - kubernetes + - metrics + kubeVersion: '>=1.21.0-0' + name: k8s-ephemeral-storage-metrics + sources: + - https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics + urls: + - https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics/releases/download/1.3.0/k8s-ephemeral-storage-metrics-1.3.0.tgz + version: 1.3.0 - annotations: artifacthub.io/license: MIT artifacthub.io/links: | @@ -155,4 +177,4 @@ entries: urls: - https://github.com/jmcgrath207/k8s-ephemeral-storage-metrics/releases/download/1.0.0/k8s-ephemeral-storage-metrics-1.0.0.tgz version: 1.0.0 -generated: "2023-11-03T18:46:23.291817062-05:00" +generated: "2023-11-26T22:34:31.469131799-06:00" diff --git a/chart/templates/DeployType.yaml b/chart/templates/DeployType.yaml index 631fc67..b4de6b3 100644 --- a/chart/templates/DeployType.yaml +++ b/chart/templates/DeployType.yaml @@ -65,14 +65,30 @@ spec: value: "{{ .Values.max_node_concurrency }}" - name: LOG_LEVEL value: "{{ .Values.log_level }}" - {{ if .Values.extra.adjusted_polling_rate }} + {{- if .Values.metrics.ephemeral_storage_pod_usage }} + - name: EPHEMERAL_STORAGE_POD_USAGE + value: "{{ .Values.metrics.ephemeral_storage_pod_usage }}" + {{- end }} + {{- if .Values.metrics.ephemeral_storage_node_available }} + - name: EPHEMERAL_STORAGE_NODE_AVAILABLE + value: "{{ .Values.metrics.ephemeral_storage_node_available }}" + {{- end }} + {{- if .Values.metrics.ephemeral_storage_node_capacity }} + - name: EPHEMERAL_STORAGE_NODE_CAPACITY + value: "{{ .Values.metrics.ephemeral_storage_node_capacity }}" + {{- end }} + {{- if .Values.metrics.ephemeral_storage_node_percentage }} + - name: EPHEMERAL_STORAGE_NODE_PERCENTAGE + value: "{{ .Values.metrics.ephemeral_storage_node_percentage }}" + {{- end }} + {{- if .Values.metrics.adjusted_polling_rate }} - name: ADJUSTED_POLLING_RATE - value: "{{ .Values.extra.adjusted_polling_rate }}" - {{ end }} - {{ if eq .Values.deploy_type "DaemonSet" }} + value: "{{ .Values.metrics.adjusted_polling_rate }}" + {{- end }} + {{- if eq .Values.deploy_type "DaemonSet" }} - name: CURRENT_NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName - {{ end }} + {{- end }} diff --git a/chart/values.yaml b/chart/values.yaml index 0ff92dc..35258cc 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -1,22 +1,33 @@ image: repository: ghcr.io/jmcgrath207/k8s-ephemeral-storage-metrics - tag: 1.2.1 + tag: 1.3.0 imagePullPolicy: IfNotPresent + +# -- Set metrics you want to enable +metrics: + # -- Current ephemeral byte usage of pod + ephemeral_storage_pod_usage: true + # -- Available ephemeral storage for a node + ephemeral_storage_node_available: true + # -- Capacity of ephemeral storage for a node + ephemeral_storage_node_capacity: true + # -- Percentage of ephemeral storage used on a node + ephemeral_storage_node_percentage: true + # -- Create the ephemeral_storage_adjusted_polling_rate metrics to report Adjusted Poll Rate in milliseconds. Typically used for testing. + adjusted_polling_rate: false + log_level: info # -- Set as Deployment for single controller to query all nodes or Daemonset deploy_type: Deployment # Note in testing, Kube API does not refresh faster than 10 seconds # -- Polling node rate for exporter interval: 15 # Seconds -# -- Max amount of concurrent query requests at a time. +# -- Max number of concurrent query requests to the kubernetes API. max_node_concurrency: 10 prometheus: enable: true release: kube-prometheus-stack -extra: - # -- Create the ephemeral_storage_adjusted_polling_rate metrics to report Adjusted Poll Rate in milliseconds. Typically used for testing. - adjusted_polling_rate: false # For local development and testing dev: diff --git a/go.mod b/go.mod index 608fd5c..2570397 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,14 @@ go 1.21 require ( github.com/cenkalti/backoff/v4 v4.2.1 - github.com/deckarep/golang-set/v2 v2.3.1 - github.com/onsi/ginkgo/v2 v2.13.0 - github.com/onsi/gomega v1.29.0 - github.com/panjf2000/ants/v2 v2.8.2 + github.com/deckarep/golang-set/v2 v2.4.0 + github.com/onsi/ginkgo/v2 v2.13.1 + github.com/onsi/gomega v1.30.0 + github.com/panjf2000/ants/v2 v2.9.0 github.com/prometheus/client_golang v1.17.0 github.com/rs/zerolog v1.31.0 - k8s.io/apimachinery v0.28.3 - k8s.io/client-go v0.28.3 + k8s.io/apimachinery v0.28.4 + k8s.io/client-go v0.28.4 ) @@ -20,7 +20,7 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/go-restful/v3 v3.10.2 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-openapi/jsonpointer v0.20.0 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.4 // indirect @@ -49,17 +49,17 @@ require ( github.com/spf13/pflag v1.0.5 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.10.0 // indirect - golang.org/x/sys v0.13.0 // indirect + golang.org/x/sys v0.14.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/time v0.3.0 // indirect - golang.org/x/tools v0.12.0 // indirect + golang.org/x/tools v0.14.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/api v0.28.3 // indirect + k8s.io/api v0.28.4 // indirect k8s.io/klog/v2 v2.100.1 // indirect k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect diff --git a/go.sum b/go.sum index 07c23c4..7022ee8 100644 --- a/go.sum +++ b/go.sum @@ -10,13 +10,13 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set/v2 v2.3.1 h1:vjmkvJt/IV27WXPyYQpAh4bRyWJc5Y435D17XQ9QU5A= -github.com/deckarep/golang-set/v2 v2.3.1/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= +github.com/deckarep/golang-set/v2 v2.4.0 h1:DnfgWKdhvHM8Kihdw9fKWXd08EdsPiyoHsk5bfsmkNI= +github.com/deckarep/golang-set/v2 v2.4.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/emicklei/go-restful/v3 v3.10.2 h1:hIovbnmBTLjHXkqEBUz3HGpXZdM7ZrE9fJIZIqlJLqE= github.com/emicklei/go-restful/v3 v3.10.2/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ= github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA= @@ -80,12 +80,12 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= -github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= -github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= -github.com/panjf2000/ants/v2 v2.8.2 h1:D1wfANttg8uXhC9149gRt1PDQ+dLVFjNXkCEycMcvQQ= -github.com/panjf2000/ants/v2 v2.8.2/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I= +github.com/onsi/ginkgo/v2 v2.13.1 h1:LNGfMbR2OVGBfXjvRZIZ2YCTQdGKtPLvuI1rMCCj3OU= +github.com/onsi/ginkgo/v2 v2.13.1/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= +github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= +github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/panjf2000/ants/v2 v2.9.0 h1:SztCLkVxBRigbg+vt0S5QvF5vxAbxbKt09/YfAJ0tEo= +github.com/panjf2000/ants/v2 v2.9.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= @@ -126,8 +126,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -143,8 +143,9 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -155,8 +156,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= @@ -174,8 +175,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= -golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -197,12 +198,12 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.28.3 h1:Gj1HtbSdB4P08C8rs9AR94MfSGpRhJgsS+GF9V26xMM= -k8s.io/api v0.28.3/go.mod h1:MRCV/jr1dW87/qJnZ57U5Pak65LGmQVkKTzf3AtKFHc= -k8s.io/apimachinery v0.28.3 h1:B1wYx8txOaCQG0HmYF6nbpU8dg6HvA06x5tEffvOe7A= -k8s.io/apimachinery v0.28.3/go.mod h1:uQTKmIqs+rAYaq+DFaoD2X7pcjLOqbQX2AOiO0nIpb8= -k8s.io/client-go v0.28.3 h1:2OqNb72ZuTZPKCl+4gTKvqao0AMOl9f3o2ijbAj3LI4= -k8s.io/client-go v0.28.3/go.mod h1:LTykbBp9gsA7SwqirlCXBWtK0guzfhpoW4qSm7i9dxo= +k8s.io/api v0.28.4 h1:8ZBrLjwosLl/NYgv1P7EQLqoO8MGQApnbgH8tu3BMzY= +k8s.io/api v0.28.4/go.mod h1:axWTGrY88s/5YE+JSt4uUi6NMM+gur1en2REMR7IRj0= +k8s.io/apimachinery v0.28.4 h1:zOSJe1mc+GxuMnFzD4Z/U1wst50X28ZNsn5bhgIIao8= +k8s.io/apimachinery v0.28.4/go.mod h1:wI37ncBvfAoswfq626yPTe6Bz1c22L7uaJ8dho83mgg= +k8s.io/client-go v0.28.4 h1:Np5ocjlZcTrkyRJ3+T3PkXDpe4UpatQxj85+xjaD2wY= +k8s.io/client-go v0.28.4/go.mod h1:0VDZFpgoZfelyP5Wqu0/r/TRYcLYuJ2U1KEeoaPa1N4= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780= diff --git a/main.go b/main.go index 823a287..d52646c 100644 --- a/main.go +++ b/main.go @@ -27,17 +27,24 @@ import ( ) var ( - inCluster string - clientset *kubernetes.Clientset - sampleInterval int64 - sampleIntervalMill int64 - adjustedPollingRate bool - adjustedTimeGaugeVec *prometheus.GaugeVec - deployType string - nodeWaitGroup sync.WaitGroup - podGaugeVec *prometheus.GaugeVec - nodeSlice []string - maxNodeConcurrency int + inCluster string + clientset *kubernetes.Clientset + sampleInterval int64 + sampleIntervalMill int64 + adjustedPollingRate bool + ephemeralStoragePodUsage bool + ephemeralStorageNodeAvailable bool + ephemeralStorageNodeCapacity bool + ephemeralStorageNodePercentage bool + adjustedTimeGaugeVec *prometheus.GaugeVec + deployType string + nodeWaitGroup sync.WaitGroup + podGaugeVec *prometheus.GaugeVec + nodeAvailableGaugeVec *prometheus.GaugeVec + nodeCapacityGaugeVec *prometheus.GaugeVec + nodePercentageGaugeVec *prometheus.GaugeVec + nodeSlice []string + maxNodeConcurrency int ) func getEnv(key, fallback string) string { @@ -175,8 +182,9 @@ func queryNode(node string) ([]byte, error) { } type CollectMetric struct { - usedBytes float64 - labels prometheus.Labels + value float64 + name string + labels prometheus.Labels } func setMetrics(node string) { @@ -188,7 +196,7 @@ func setMetrics(node string) { content, err := queryNode(node) if err != nil { - // Could not query node, skip + log.Warn().Msg(fmt.Sprintf("Could not query node: %s. Skipping..", node)) return } @@ -201,17 +209,50 @@ func setMetrics(node string) { podName := pod.PodRef.Name podNamespace := pod.PodRef.Namespace usedBytes := pod.EphemeralStorage.UsedBytes + availableBytes := pod.EphemeralStorage.AvailableBytes + capacityBytes := pod.EphemeralStorage.CapacityBytes if podNamespace == "" || (usedBytes == 0 && pod.EphemeralStorage.AvailableBytes == 0 && pod.EphemeralStorage.CapacityBytes == 0) { log.Warn().Msg(fmt.Sprintf("pod %s/%s on %s has no metrics on its ephemeral storage usage", podName, podNamespace, nodeName)) log.Warn().Msg(fmt.Sprintf("raw content %v", content)) } - labelsList = append(labelsList, CollectMetric{ - usedBytes, - prometheus.Labels{"pod_namespace": podNamespace, - "pod_name": podName, "node_name": nodeName}, - }) - log.Debug().Msg(fmt.Sprintf("pod %s/%s on %s with usedBytes: %f", podNamespace, podName, nodeName, usedBytes)) + if ephemeralStoragePodUsage { + labelsList = append(labelsList, CollectMetric{ + value: usedBytes, + name: "ephemeral_storage_pod_usage", + labels: prometheus.Labels{"pod_namespace": podNamespace, + "pod_name": podName, "node_name": nodeName}, + }) + log.Debug().Msg(fmt.Sprintf("pod %s/%s on %s with usedBytes: %f", podNamespace, podName, nodeName, usedBytes)) + } + if ephemeralStorageNodeAvailable { + labelsList = append(labelsList, CollectMetric{ + value: availableBytes, + name: "ephemeral_storage_node_available", + labels: prometheus.Labels{"node_name": nodeName}}, + ) + log.Debug().Msg(fmt.Sprintf("Node: %s availble bytes: %f", nodeName, availableBytes)) + } + + if ephemeralStorageNodeCapacity { + labelsList = append(labelsList, CollectMetric{ + value: capacityBytes, + name: "ephemeral_storage_node_capacity", + labels: prometheus.Labels{"node_name": nodeName}}, + ) + log.Debug().Msg(fmt.Sprintf("Node: %s capacity bytes: %f", nodeName, capacityBytes)) + } + + if ephemeralStorageNodeCapacity { + percentage := (availableBytes / capacityBytes) * 100.0 + labelsList = append(labelsList, CollectMetric{ + value: percentage, + name: "ephemeral_storage_node_percentage", + labels: prometheus.Labels{"node_name": nodeName}}, + ) + log.Debug().Msg(fmt.Sprintf("Node: %s percentage used: %f", nodeName, percentage)) + } + } // Reset Metrics for this Node name to remove dead pods @@ -219,7 +260,17 @@ func setMetrics(node string) { // Push new metrics to exporter for _, x := range labelsList { - podGaugeVec.With(x.labels).Set(x.usedBytes) + switch x.name { + case "ephemeral_storage_pod_usage": + podGaugeVec.With(x.labels).Set(x.value) + case "ephemeral_storage_node_available": + nodeAvailableGaugeVec.With(x.labels).Set(x.value) + case "ephemeral_storage_node_capacity": + nodeCapacityGaugeVec.With(x.labels).Set(x.value) + case "ephemeral_storage_node_percentage": + nodePercentageGaugeVec.With(x.labels).Set(x.value) + } + } adjustTime := sampleIntervalMill - time.Now().Sub(start).Milliseconds() @@ -233,21 +284,67 @@ func setMetrics(node string) { } func createMetrics() { - podGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: "ephemeral_storage_pod_usage", - Help: "Used to expose Ephemeral Storage metrics for pod in bytes ", - }, - []string{ - // name of pod for Ephemeral Storage - "pod_name", - // namespace of pod for Ephemeral Storage - "pod_namespace", - // Name of Node where pod is placed. - "node_name", + + if ephemeralStoragePodUsage { + podGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ephemeral_storage_pod_usage", + Help: "Current ephemeral byte usage of pod", }, - ) + []string{ + // name of pod for Ephemeral Storage + "pod_name", + // namespace of pod for Ephemeral Storage + "pod_namespace", + // Name of Node where pod is placed. + "node_name", + }, + ) + + prometheus.MustRegister(podGaugeVec) - prometheus.MustRegister(podGaugeVec) + } + + if ephemeralStorageNodeAvailable { + nodeAvailableGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ephemeral_storage_node_available", + Help: "Available ephemeral storage for a node", + }, + []string{ + // Name of Node where pod is placed. + "node_name", + }, + ) + + prometheus.MustRegister(nodeAvailableGaugeVec) + } + + if ephemeralStorageNodeCapacity { + nodeCapacityGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ephemeral_storage_node_capacity", + Help: "Capacity of ephemeral storage for a node", + }, + []string{ + // Name of Node where pod is placed. + "node_name", + }, + ) + + prometheus.MustRegister(nodeCapacityGaugeVec) + } + + if ephemeralStorageNodePercentage { + nodePercentageGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "ephemeral_storage_node_percentage", + Help: "Percentage of ephemeral storage used on a node", + }, + []string{ + // Name of Node where pod is placed. + "node_name", + }, + ) + + prometheus.MustRegister(nodePercentageGaugeVec) + } if adjustedPollingRate { adjustedTimeGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ @@ -309,6 +406,10 @@ func main() { flag.Parse() port := getEnv("METRICS_PORT", "9100") adjustedPollingRate, _ = strconv.ParseBool(getEnv("ADJUSTED_POLLING_RATE", "false")) + ephemeralStoragePodUsage, _ = strconv.ParseBool(getEnv("EPHEMERAL_STORAGE_POD_USAGE", "false")) + ephemeralStorageNodeAvailable, _ = strconv.ParseBool(getEnv("EPHEMERAL_STORAGE_NODE_AVAILABLE", "false")) + ephemeralStorageNodeCapacity, _ = strconv.ParseBool(getEnv("EPHEMERAL_STORAGE_NODE_CAPACITY", "false")) + ephemeralStorageNodePercentage, _ = strconv.ParseBool(getEnv("EPHEMERAL_STORAGE_NODE_PERCENTAGE", "false")) deployType = getEnv("DEPLOY_TYPE", "DaemonSet") sampleInterval, _ = strconv.ParseInt(getEnv("SCRAPE_INTERVAL", "15"), 10, 64) maxNodeConcurrency, _ = strconv.Atoi(getEnv("MAX_NODE_CONCURRENCY", "10")) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 73d7b5c..33a3175 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -29,7 +29,7 @@ function main() { "deploy_type=Deployment", "log_level=debug" "dev.enabled=true", - "extra.adjusted_polling_rate=true" + "metrics.adjusted_polling_rate=true" ) if [[ $ENV =~ "e2e" ]]; then diff --git a/tests/e2e/deployment_test.go b/tests/e2e/deployment_test.go index dca237c..a482ff5 100644 --- a/tests/e2e/deployment_test.go +++ b/tests/e2e/deployment_test.go @@ -107,6 +107,18 @@ func checkPrometheus(checkSlice []string) { } +func WatchNodePercentage() { + status := 0 + re := regexp.MustCompile(`ephemeral_storage_node_percentage\{node_name="ephemeral-metrics-cluster-control-plane"}\s+(.+)`) + output := requestPrometheusString() + match := re.FindAllStringSubmatch(output, -1) + floatValue, _ := strconv.ParseFloat(match[0][1], 64) + if floatValue < 100.0 { + status = 1 + } + gomega.Expect(status).Should(gomega.Equal(1)) + +} func WatchPollingRate(pollRateUpper float64, pollingRateLower float64, timeout time.Duration) { status := 0 startTime := time.Now() @@ -179,6 +191,9 @@ var _ = ginkgo.Describe("Test Metrics\n", func() { ginkgo.Specify("\nReturn A Record IP addresses and Proxy IP address", func() { var checkSlice []string checkSlice = append(checkSlice, "ephemeral_storage_pod_usage", + "ephemeral_storage_node_available", + "ephemeral_storage_node_capacity", + "ephemeral_storage_node_percentage", "pod_name=\"k8s-ephemeral-storage", "ephemeral_storage_adjusted_polling_rate", "node_name=\"ephemeral-metrics-cluster-worker", "node_name=\"ephemeral-metrics-cluster-control-plane") checkPrometheus(checkSlice) @@ -193,10 +208,15 @@ var _ = ginkgo.Describe("Test Metrics\n", func() { }) }) ginkgo.Context("Test Polling speed\n", func() { - ginkgo.Specify("\nMake sure Adjusted Poll rate is between 5000 - 4000 ms ", func() { + ginkgo.Specify("\nMake sure Adjusted Poll rate is between 5000 - 4000 ms", func() { WatchPollingRate(5000.0, 4000.0, time.Second*90) }) }) + ginkgo.Context("Test ephemeral_storage_node_percentage\n", func() { + ginkgo.Specify("\nMake sure percentage is not over 100", func() { + WatchNodePercentage() + }) + }) }) func TestDeployments(t *testing.T) {