Kubernetes 1.31 SIG Instrumentation の変更内容

- [Kubernetes 1.29 SIG Instrumentation の変更内容](https://qiita.com/watawuwu/items/d6c63744ba8b65cea748)
- [Kubernetes 1.30 SIG Instrumentation の変更内容](https://qiita.com/watawuwu/items/09b929fa5537babeaf6e)

## はじめに

ここでは Kubernetes v1.31 の [Changelog](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.31.md) から、メトリクスの変更点と SIG Instrumentation の取り組みについてまとめました。

Kubernetes v1.31 で大きく更新された SIG Instrumentation の KEP はないため、メトリクスに関連する更新内容を抜粋した内容のみを紹介します。

## メトリクスの変更

### kube-apiserver

<!-- - Exposed the `apiserver_watch_cache_resource_version` metric to simplify debugging problems with watchcache. ([#125377](https://github.com/kubernetes/kubernetes/pull/125377), [@wojtek-t](https://github.com/wojtek-t)) [SIG API Machinery and Instrumentation] -->
- :new: デバッグのためにリソースバージョンを記録するメトリクスが追加されました([#125377](https://github.com/kubernetes/kubernetes/pull/125377), [@&#xFFF0;wojtek-t](https://github.com/wojtek-t))
  - Gauge: `apiserver_watch_cache_resource_version`
    - Labels: {"resource"}
<!-- - Promoted the metrics for both ValidatingAdmissionPolicy (VAP) and CustomResourceDefinition (CRD) validation rules to beta. ([#126237](https://github.com/kubernetes/kubernetes/pull/126237), [@&#xFFF0;cici37](https://github.com/cici37)) [SIG API Machinery and Instrumentation] -->
- :up: ValidatingAdmissionPolicy (VAP) と CustomResourceDefinition (CRD) のバリデーションルールのメトリクスがベータに昇格しました([#126237](https://github.com/kubernetes/kubernetes/pull/126237), [@&#xFFF0;cici37](https://github.com/cici37))
  - Counter: `apiserver_validating_admission_policy_check_total`
    - Labels: {"policy", "policy_binding", "error_type", "enforcement_action"}
  - Histogram: `apiserver_validating_admission_policy_check_duration_seconds`
    - Labels: {"policy", "policy_binding", "error_type", "enforcement_action"}
  - Histogram: `apiserver_cel_compilation_duration_seconds`
    - Labels: {"policy", "policy_binding", "error_type", "enforcement_action"}
  - Histogram: `apiserver_cel_evaluation_duration_seconds`
    - Labels: {"policy", "policy_binding", "error_type", "enforcement_action"}

### kubelet

<!-- - Added `storage_class` and `volume_attributes_class` labels to `pv_collector_bound_pvc_count` and `pv_collector_unbound_pvc_count` metrics. ([#126166](https://github.com/kubernetes/kubernetes/pull/126166), [@&#xFFF0;AndrewSirenko](https://github.com/AndrewSirenko)) -->
- :up: VolumeAttributesClass フィーチャーの可観測性を強化するため、次のメトリクスにラベルが追加されました。これにより、バインドできない StorageClass と VolumeAttributesClass の確認が容易になりました。([#126166](https://github.com/kubernetes/kubernetes/pull/126166), [@&#xFFF0;AndrewSirenko](https://github.com/AndrewSirenko))
  - Gauge: `pv_collector_bound_pvc_count`
    - Labels: {"namespace", "storage_class", "volume_attributes_class"}
  - Gauge: `pv_collector_unbound_pvc_count`
    - Labels: {"namespace", "storage_class", "volume_attributes_class"}

### kube-scheduler

<!-- - Implemented `event_handling_duration_seconds` metric, which is the time the scheduler takes to handle each kind of events. ([#125929](https://github.com/kubernetes/kubernetes/pull/125929), [@&#xFFF0;sanposhiho](https://github.com/sanposhiho)) -->
- :new: スケジューラーでイベントの処理時間を計測するメトリクスが追加されました([#125929](https://github.com/kubernetes/kubernetes/pull/125929), [@&#xFFF0;sanposhiho](https://github.com/sanposhiho))
  - Histogram: `scheduler_event_handling_duration_seconds`
    - Labels: {"event"}
<!-- - Implemented `queueing_hint_execution_duration_seconds` metric, which is the time the QueueingHint function takes. ([#126227](https://github.com/kubernetes/kubernetes/pull/126227), [@&#xFFF0;sanposhiho](https://github.com/sanposhiho)) -->
- :new: `scheduler_event_handling_duration_seconds` メトリクスに加え、ボトルネックをより明確に把握するため、QueueingHint 実行時間を計測するメトリクスが追加されました([#126227](https://github.com/kubernetes/kubernetes/pull/126227), [@&#xFFF0;sanposhiho](https://github.com/sanposhiho))
  - Histogram: `scheduler_queueing_hint_execution_duration_seconds`
    - Labels: {"plugin", "event", "hint"}
<!-- - Fixed a typo in the help text for the pod_scheduling_sli_duration_seconds metric in kube-scheduler. ([#124221](https://github.com/kubernetes/kubernetes/pull/124221), [@&#xFFF0;arturhoo](https://github.com/arturhoo)) [SIG Instrumentation, Scheduling and Testing] -->
- :bug: HELP テキストのタイプミスが修正されました([#124221](https://github.com/kubernetes/kubernetes/pull/124221), [@&#xFFF0;arturhoo](https://github.com/arturhoo))
  - Histogram: `scheduler_pod_scheduling_sli_duration_seconds`
    - Labels: {"attempts"}

### kube-proxy

<!-- - Added support for kube-proxy iptables mode to track packets that were wrongfully marked invalid by conntrack and subsequently dropped by introducing `kubeproxy_iptables_ct_state_invalid_dropped_packets_total` metric. ([#122812](https://github.com/kubernetes/kubernetes/pull/122812), [@&#xFFF0;aroradaman](https://github.com/aroradaman)) [SIG Instrumentation, Network and Testing] -->
- :new: kube-proxy の iptables モードに、Conntrack によって無効とマークされ、ドロップされたパケットを追跡するメトリクスが追加されました([#122812](https://github.com/kubernetes/kubernetes/pull/122812), [@&#xFFF0;aroradaman](https://github.com/aroradaman))
  - Counter: `kubeproxy_iptables_ct_state_invalid_dropped_packets_total`
<!-- - The iptables mode of kube-proxy now tracks accepted packets that are destined for node-ports on localhost by introducing `kubeproxy_iptables_localhost_nodeports_accepted_packets_total` metric. This will help users to identify if they rely on iptables.localhostNodePorts feature and ulitmately help them to migrate from iptables to nftables. ([#125015](https://github.com/kubernetes/kubernetes/pull/125015), [@&#xFFF0;aroradaman](https://github.com/aroradaman)) [SIG Instrumentation, Network and Testing] -->
- :new: kube-proxy の iptables モードに、iptables から nftables への移行支援のため、iptables.localhostNodePorts 機能に依存しているかどうかを特定するためのメトリクスが追加されました([#125015](https://github.com/kubernetes/kubernetes/pull/125015), [@&#xFFF0;aroradaman](https://github.com/aroradaman))
  - Counter: `kubeproxy_iptables_localhost_nodeports_accepted_packets_total`
<!-- - Added metrics for the nftables kube-proxy mode rather than it reporting metrics with "iptables" in their names. ([#124557](https://github.com/kubernetes/kubernetes/pull/124557), [@&#xFFF0;danwinship](https://github.com/danwinship)) [SIG Network and Windows] -->
- :new: kube-proxy の nftables モードに対応したメトリクスが追加されました([#124557](https://github.com/kubernetes/kubernetes/pull/124557), [@&#xFFF0;danwinship](https://github.com/danwinship))
  - Counter: `kubeproxy_sync_proxy_rules_nftables_sync_failures_total`
  - Counter: `kubeproxy_sync_proxy_rules_nftables_cleanup_failures_total`

## メトリクス以外の変更点

<!-- - Component-base/logs: when compiled with Go >= 1.21, component-base will automatically configure the slog default logger together with initializing klog. ([#120696](https://github.com/kubernetes/kubernetes/pull/120696), [@&#xFFF0;pohly](https://github.com/pohly)) -->
- Component-base/logs: Go 1.21 以降でコンパイルした場合、component-base は klog の初期化とともに、slog デフォルトロガーを自動的に設定します([#120696](https://github.com/kubernetes/kubernetes/pull/120696), [@&#xFFF0;pohly](https://github.com/pohly))
<!-- - Migrated the pkg/proxy to use [contextual logging](https://k8s.io/docs/concepts/cluster-administration/system-logs/#contextual-logging). ([#122979](https://github.com/kubernetes/kubernetes/pull/122979), [@&#xFFF0;fatsheep9146](https://github.com/fatsheep9146)) -->
- pkg/proxy が [contextual logging](https://k8s.io/docs/concepts/cluster-administration/system-logs/#contextual-logging) に移行しました([#122979](https://github.com/kubernetes/kubernetes/pull/122979), [@&#xFFF0;fatsheep9146](https://github.com/fatsheep9146))
<!-- - Optimized log output to avoid printing out redundant information of the pod. ([#124055](https://github.com/kubernetes/kubernetes/pull/124055), [@&#xFFF0;yangjunmyfm192085](https://github.com/yangjunmyfm192085)) -->
- klog.KObj 関数を利用して、Pod 情報のログ出力を最適化しました([#124055](https://github.com/kubernetes/kubernetes/pull/124055), [@&#xFFF0;yangjunmyfm192085](https://github.com/yangjunmyfm192085))

## 参考

- [Kubernetes Metrics Reference](https://kubernetes.io/docs/reference/instrumentation/metrics/)
  - 2024-08-20 の記載時点では v1.30 までの内容となっています
  - [History for content/en/docs/reference/instrumentation/metrics.md - kubernetes/website](https://github.com/kubernetes/website/commits/main/content/en/docs/reference/instrumentation/metrics.md)