Skip to content

NimTechnology

Trình bày các công nghệ CLOUD một cách dễ hiểu.

  • Kubernetes & Container
    • Docker
    • Kubernetes
      • Ingress
      • Pod
    • Helm Chart
    • OAuth2 Proxy
    • Isito-EnvoyFilter
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Vault
    • Longhorn – Storage
    • VictoriaMetrics
    • MetalLB
    • Kong Gateway
  • CI/CD
    • ArgoCD
    • ArgoWorkflows
    • Argo Events
    • Spinnaker
    • Jenkins
    • Harbor
    • TeamCity
    • Git
      • Bitbucket
  • Coding
    • DevSecOps
    • Terraform
      • GCP – Google Cloud
      • AWS – Amazon Web Service
      • Azure Cloud
    • Golang
    • Laravel
    • Python
    • Jquery & JavaScript
    • Selenium
  • Log, Monitor & Tracing
    • DataDog
    • Prometheus
    • Grafana
    • ELK
      • Kibana
      • Logstash
  • BareMetal
    • NextCloud
  • Toggle search form

[Prometheus/Istio] Research about Recording Rules in Prometheus and reduce metrics of istio cluster.

Posted on December 15, 2021December 24, 2021 By nim No Comments on [Prometheus/Istio] Research about Recording Rules in Prometheus and reduce metrics of istio cluster.

Note lần này sẽ giúp chúng ta tìm hiểu về:
– Recording Rules trong prometheus.
– Giảm metrics của istio. Từ đó giảm ram của prometheus.

Liệu việc giảm ram của prometheus bằng các giảm metrics thì có thực sự hiệu quả?

https://karlstoney.com/2020/02/25/federated-prometheus-to-reduce-metric-cardinality/

Giờ chúng ta sẽ đi tìm hiều Recording Rules trong 1 ví dụ thực tế với istio.

Hiện tại thì con prometheus của mình đang sử dụng quá nhiều ram.

Nếu nhà giàu thì thêm ram cho node, nhưng mà nhà mình nghèo các bạn ạ.

Theo như bài viết sau:
https://karlstoney.com/2020/02/25/federated-prometheus-to-reduce-metric-cardinality/
– thì mình sử dụng Record rule để remove the cardinality( Loại bỏ các data không cần thiết trong metrics) and get us back to a concise set of service metrics (đưa về dạng ngắn gọn và vừa đủ dùng).
– và bạn cũng sẽ thấy dùng irate để giảm số lương metrics lại, như trên con collector là 100 thì khi chuyển lên con master chỉ còn 10.

[Prometheus/Kiali] Setting Prometheus or Kiali for multi-cluster Istio mode.
Ở bài viết trên là mình có nhiều con prometheus trên mỗi cluster với nhiều vụ là collector
Và có 1 con prometheus ở cluster chính đi lấy lại metrics của các collector

Theo như bài viết kia thì mình cần giảm data (nghĩ là bỏ mấy text dư thừa) trong các metrics sau:
– istio_request_duration_milliseconds_bucket
– istio_request_bytes_bucket
– istio_response_bytes_bucket
– istio_requests_total

Contents

Toggle
  • 1) Recording Rules
  • 2) federate in mode “master and collector” Of Prometheus
  • 3) Summary
    • 3.1) Problem.
    • 3.2) Resolve problem.
      • 3.2.1) Grafana
      • 3.2.2) Kiali.
  • 4) Redude data size of metrics. Using envoyfile.

1) Recording Rules

Mình sẽ lấy thử 1 metric cái ra làm demo: istio_request_duration_milliseconds_bucket

Để hiểu tại sao chúng ta cần bỏ cái j và sau khi bỏ thì grafana hết chạy!!!!

giờ bạn đi tìm: istio_request_duration_milliseconds_bucket nằm trong chart nào?

Mình list ra essential keys bên trong metric.
Ở đây thì có key đặc biệt: connection_security_policy=”mutual_tls” Bạn thấy nó có hình ổ khoá
Cái này mình check lại nếu có lỗi

reporter,
connection_security_policy,
source_workload,
source_workload_namespace,
destination_service,
destination_workload,
destination_workload_namespace,
le

Trong bài biết của anh tây thì anh lại query reporter=”source”

Nếu mình query kiểu đó thì trường connection_security_policy bị “unknown”
mình đoán chart của mình có khả năng sai.
  recording_rules.yml: |
    groups:
      - name: istio.workload.istio_request_duration_milliseconds_bucket
        interval: 10s
        rules:
          - record: federate:istio_request_duration_milliseconds_bucket:rate1m
            expr: |
              sum(irate(istio_request_duration_milliseconds_bucket{source_workload!=""}[1m]))
                by (
                  connection_security_policy,
                  source_workload,
                  source_workload_namespace,
                  destination_service,
                  destination_workload,
                  destination_workload_namespace,
                  le
                )
  rules: |
    {}

sau khi thêm vào config map của prometheus.

thì nó 1 thành phần để auto reload configmap he.
nên ko redeploy lại prometheus
Kiểm tra trên UI prometheus nếu thấy như này là ngon.

Nếu bạn thấy trắng bóc thì sem log của con reload và con prometheus.

khi bạn click vào đây nó thực hiện query ở phần exp và nhận được kết quả:
Bạn thấy data trong metric được lược bỏ khá nhiều
Đây là data trước đó khi được rule lại

2) federate in mode “master and collector” Of Prometheus

Mình qua con prometheus chính:

    # remote cluster
    - job_name: 'federate'
      scrape_interval: 10s
      honor_labels: true
      metrics_path: '/federate'
      params:
        'match[]':
          - '{__name__=~"federate:(.*)"}'
      static_configs:
      - targets:
        - '192.168.101.51:32166'
        labels:
          cluster: 'cluster2'
      metric_relabel_configs:
      - source_labels: [__name__]
        regex: 'federate:(.*)'
        target_label: __name__
        action: replace

There are a couple of important points here. Firstly, we’re telling Prometheus to only scrape metrics that start with federate:, this is why that convention earlier was important.

Secondly, we then relabel the metric to remove the federate: prefix. Meaning in our top-level Prometheus our metrics will be clearer. federate:istio_request_bytes_bucket:rate1m 
becomes istio_request_bytes_bucket:rate1m.

Mình có giải dễ hiều về metric_relabel_configs trong case này ở link bên dưới
https://nimtechnology.com/2021/12/15/prometheus-relabelling-custom-name-to-your-mind/

Mình sẽ kiểm chứng câu nói trên:

khi click vào đây

show trang metrics

Bạn thấy __name__ là federate:istio_request_duration_milliseconds_bucket:rate1m

__name__ của metric được bắt đầu bằng federate:****

Nhờ cái metric_relabel_configs thì name query được trên prometheus master sẽ là: istio_request_duration_milliseconds_bucket:rate1m

khi query là “federate:istio_request_duration_milliseconds_bucket:rate1m”
thì ko có data bị chúng ta đã relabel
có data khi query là: “istio_request_duration_milliseconds_bucket:rate1m”

3) Summary

3.1) Problem.

Tác giả có bảo:

And that’s it, that’s literally all you need to do. At this point, you should have metrics being federated into your top-level Prometheus! You can get an idea of the savings by running count({__name__=~"istio.*"}) in both your collector and master. In our case:

  • collector: count({__name__=~"istio.*"}) 337635
  • master: count({__name__=~"istio.*"}) 10143

An unbelievable reduction. To put this into context, we have 330 workloads with over 1000 pods, and our production Prometheus is running using 2.5GB memory.

Hay ta giảm metrics kìa:
Chúng ta sẽ có chữ nhưng:
1) chúng ta cần change query trên grafana từ istio_request_duration_milliseconds_bucket
thành istio_request_duration_milliseconds_bucket:rate1m


– việc này khá câù kì vì bạn thấy từ đầu bài viết đến giờ chúng ta cần khá nhiều bước.
2) Cách này sẽ độ delay nhất định như tác giả cũng đã nhắc:

Note the interesting part here, each rule goes into its own group, this is intentional as each rule takes about 4-5 seconds to evaluate on our instance. Remember how I said earlier that rules are evaluated in series, within a group. Therefore, if they were in the same group, this it would take 16-20s to complete evaluation.

This is extremely important, especially when you’re visualizing your data in grafana. If your rule group is taking 30+ seconds to run, your graphs are going to look very clunky, as you only have a snapshot of the data every 30 seconds.

For us, with each group taking 4-5s, plus the 10 second interval means we get the rule recorded around every 15 seconds. Which loosely matches our step_interval in grafana. Perfect.

Với các metrics it thì mình thấy nó bị đứt đoạn:

3) Thông số của grafana trả về thì ko match với kết quả test

echo "GET http://192.168.101.51:30765/api/vehicles/driver/City%20Truck" | vegeta attack -duration=600s -rate=200 | vegeta report --type=text
Requests      [total, rate, throughput]         120000, 200.00, 200.00
Duration      [total, attack, wait]             10m0s, 10m0s, 16.396ms
Latencies     [min, mean, 50, 90, 95, 99, max]  2.873ms, 4.905ms, 4.331ms, 6.757ms, 8.085ms, 12.016ms, 257.235ms
Bytes In      [total, mean]                     10200000, 85.00
Bytes Out     [total, mean]                     0, 0.00
Success       [ratio]                           100.00%
Status Codes  [code:count]                      200:120000  

Mình gửi vào 200 req/s thì chặc hiện ít hơn nhiều so với kết quả mình test

nếu cộng tổng thì chắc ở đây tâm 40 req/s


Ở bài viết này thì chúng học được cách Recording Rules và relabel configs

Còn về việc giảm metrics rồi giảm ram prometheus thì cần xem sét lại.

  recording_rules.yml: |
    groups:
      - name: istio.workload.istio_request_duration_milliseconds_bucket
        interval: 10s
        rules:
          - record: federate:istio_request_duration_milliseconds_bucket:rate1m
            expr: |
              sum(irate(istio_request_duration_milliseconds_bucket{source_workload!=""}[1m]))
                by (
                  reporter,
                  connection_security_policy,
                  source_workload,
                  source_workload_namespace,
                  destination_service,
                  destination_workload,
                  destination_workload_namespace,
                  le
                )
      - name: istio.workload.istio_response_bytes_bucket
        interval: 10s
        rules:

          - record: federate:istio_response_bytes_bucket:rate1m
            expr: |
              sum(irate(istio_response_bytes_bucket{source_workload!=""}[1m]))
                by (
                  reporter,
                  connection_security_policy,
                  source_workload,
                  source_workload_namespace,
                  destination_service,
                  destination_workload,
                  destination_workload_namespace,
                  le
                )
      - name: istio.workload.istio_requests_total
        interval: 10s
        rules:
          - record: federate:istio_requests_total:rate1m
            expr: |
              sum(irate(istio_requests_total{source_workload!=""}[1m]))
                by (
                  reporter,
                  connection_security_policy,
                  source_workload,
                  source_workload_namespace,
                  destination_service,
                  destination_workload,
                  destination_workload_namespace,
                  response_code,
                  response_flags
                )

3.2) Resolve problem.

3.2.1) Grafana

Về vấn để chart grafana bị đứt đoạn:

This image has an empty alt attribute; its file name is image-117.png

Mình mới nghĩ ra bị bên các collector mình đã irate[1m] thì chart grafana get data từ master ko cần có tham số irate nữa.

sau khi remote irate có vẻ chart chính sác hơn

3.2.2) Kiali.

Vì đang chạy mô hình multi cluster istio và mình cũng mong muốn istio hiện thị multi cluster.

Bạn có thể tham khảo link sau:
https://nimtechnology.com/2021/12/12/prometheus-kiali-setting-prometheus-or-kiali-for-multi-cluster-istio-mode/#2_Kiali

Buồn 1 cài khi custom như thế này là chắc chắn mất chart multi cluster trên kiali.

Mình có tìm hiều thì kiali sẽ cần 1 số metric ở prometheus:
https://kiali.io/docs/architecture/architecture/#prometheus

Và đó là những metrics gì thì hình như là ở đây:
https://istio.io/latest/docs/reference/config/metrics/

Nếu có thời gian mình sẽ lab và kiểm chứng.

4) Redude data size of metrics. Using envoyfile.

Links than khảo:
https://karlstoney.com/2020/05/25/reduce-istio-sidecar-metric-cardinality/

Nói chung cách thức ok. Nhưng bạn lưa chọn remove label 1 các hợp lý nhé.

Isito-EnvoyFilter, Prometheus

Post navigation

Previous Post: [Grafana/Prometheus/Istio] How does prometheus get istio metrics?
Next Post: [Prometheus] Relabelling – Custom “__name__” to your mind

More Related Articles

[Kubernetes] Monitor Persistent Volume usage in Kubernetes using Prometheus Prometheus
[Node exporter] Install node_exporter on MacOS BareMetal
[Istio] Analyzing Istio Performance by pprof Isito-EnvoyFilter
[Istio] Security authentication và authorization with ISTIO Isito-EnvoyFilter
[Upgrade Canary Istio Cluster] Do you want to upgrade the new version for Your Multi-Cluster Isito? Welcome to Nimtechnology. Very easy!!! That right. Isito-EnvoyFilter
[Node exporter] Install node_exporter on Linux by a script file! BareMetal

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tham Gia Group DevOps nhé!
Để Nim có nhiều động lực ra nhiều bài viết.
Để nhận được những thông báo mới nhất.

Recent Posts

  • [Azure] The subscription is not registered to use namespace ‘Microsoft.ContainerService’ May 8, 2025
  • [Azure] Insufficient regional vcpu quota left May 8, 2025
  • [WordPress] How to add a Dynamic watermark on WordPress. May 6, 2025
  • [vnet/Azure] VNet provisioning via Terraform. April 28, 2025
  • [tracetcp] How to perform a tracert command using a specific port. April 3, 2025

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • July 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Categories

  • BareMetal
    • NextCloud
  • CI/CD
    • Argo Events
    • ArgoCD
    • ArgoWorkflows
    • Git
      • Bitbucket
    • Harbor
    • Jenkins
    • Spinnaker
    • TeamCity
  • Coding
    • DevSecOps
    • Golang
    • Jquery & JavaScript
    • Laravel
    • NextJS 14 & ReactJS & Type Script
    • Python
    • Selenium
    • Terraform
      • AWS – Amazon Web Service
      • Azure Cloud
      • GCP – Google Cloud
  • Kubernetes & Container
    • Apache Kafka
      • Kafka
      • Kafka Connect
      • Lenses
    • Docker
    • Helm Chart
    • Isito-EnvoyFilter
    • Kong Gateway
    • Kubernetes
      • Ingress
      • Pod
    • Longhorn – Storage
    • MetalLB
    • OAuth2 Proxy
    • Vault
    • VictoriaMetrics
  • Log, Monitor & Tracing
    • DataDog
    • ELK
      • Kibana
      • Logstash
    • Fluent
    • Grafana
    • Prometheus
  • Uncategorized
  • Admin

Copyright © 2025 NimTechnology.