From 06ba0c82cd0c4c360452684456b117bf0d891a76 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Sat, 20 Apr 2024 19:28:38 +0100 Subject: [PATCH] Switch JSON serialization to camel case (#17) JSON serialization of fields uses camel case instead of snake case. --- CHANGELOG.md | 4 ++++ metrics/external/external.go | 2 +- metrics/object/object.go | 2 +- metrics/podmetrics/podmetrics.go | 6 +++--- metrics/pods/pods.go | 10 +++++----- metrics/resource/resource.go | 10 +++++----- metrics/value/value.go | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d494af5..8ced194 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- **BREAKING CHANGE** Types now use JSON tags which match Kubernetes convention, with naming using camel case rather +than snake case. For example the Resource Metric field `PodMetricsInfo` is now serialized as `podMetricsInfo` rather +than `pod_metrics_info`. ## [v3.0.0] - 2024-03-21 ### Changed diff --git a/metrics/external/external.go b/metrics/external/external.go index daadede..60f0181 100644 --- a/metrics/external/external.go +++ b/metrics/external/external.go @@ -28,6 +28,6 @@ import ( // service, or QPS from loadbalancer running outside of cluster). type Metric struct { Current value.MetricValue `json:"current,omitempty"` - ReadyPodCount *int64 `json:"ready_pod_count,omitempty"` + ReadyPodCount *int64 `json:"readyPodCount,omitempty"` Timestamp time.Time `json:"timestamp,omitempty"` } diff --git a/metrics/object/object.go b/metrics/object/object.go index ca56ea4..11b7cce 100644 --- a/metrics/object/object.go +++ b/metrics/object/object.go @@ -26,6 +26,6 @@ import ( // Metric (Object) is a metric describing a kubernetes object (for example, hits-per-second on an Ingress object). type Metric struct { Current value.MetricValue `json:"current,omitempty"` - ReadyPodCount *int64 `json:"ready_pod_count,omitempty"` + ReadyPodCount *int64 `json:"readyPodCount,omitempty"` Timestamp time.Time `json:"timestamp,omitempty"` } diff --git a/metrics/podmetrics/podmetrics.go b/metrics/podmetrics/podmetrics.go index 2344318..665177f 100644 --- a/metrics/podmetrics/podmetrics.go +++ b/metrics/podmetrics/podmetrics.go @@ -21,9 +21,9 @@ import "time" // Metric contains pod metric value (the metric values are expected to be the metric as a milli-value) type Metric struct { - Timestamp time.Time - Window time.Duration - Value int64 + Timestamp time.Time `json:"timestamp"` + Window time.Duration `json:"window"` + Value int64 `json:"value"` } // MetricsInfo contains pod metrics as a map from pod names to MetricsInfo diff --git a/metrics/pods/pods.go b/metrics/pods/pods.go index 344abfa..6799f58 100644 --- a/metrics/pods/pods.go +++ b/metrics/pods/pods.go @@ -27,10 +27,10 @@ import ( // Metric (Pods) is a metric describing each pod in the current scale target (for example, // transactions-processed-per-second). The values will be averaged together before being compared to the target value. type Metric struct { - PodMetricsInfo podmetrics.MetricsInfo `json:"pod_metrics_info"` - ReadyPodCount int64 `json:"ready_pod_count"` - IgnoredPods sets.String `json:"ignored_pods"` - MissingPods sets.String `json:"missing_pods"` - TotalPods int `json:"total_pods"` + PodMetricsInfo podmetrics.MetricsInfo `json:"podMetricsInfo"` + ReadyPodCount int64 `json:"readyPodCount"` + IgnoredPods sets.String `json:"ignoredPods"` + MissingPods sets.String `json:"missingPods"` + TotalPods int `json:"totalPods"` Timestamp time.Time `json:"timestamp,omitempty"` } diff --git a/metrics/resource/resource.go b/metrics/resource/resource.go index 5053d7a..ce05a41 100644 --- a/metrics/resource/resource.go +++ b/metrics/resource/resource.go @@ -28,11 +28,11 @@ import ( // in the current scale target (e.g. CPU or memory). Such metrics are built in to Kubernetes, and have special scaling // options on top of those available to normal per-pod metrics (the "pods" source). type Metric struct { - PodMetricsInfo podmetrics.MetricsInfo `json:"pod_metrics_info"` + PodMetricsInfo podmetrics.MetricsInfo `json:"podMetricsInfo"` Requests map[string]int64 `json:"requests"` - ReadyPodCount int64 `json:"ready_pod_count"` - IgnoredPods sets.String `json:"ignored_pods"` - MissingPods sets.String `json:"missing_pods"` - TotalPods int `json:"total_pods"` + ReadyPodCount int64 `json:"readyPodCount"` + IgnoredPods sets.String `json:"ignoredPods"` + MissingPods sets.String `json:"missingPods"` + TotalPods int `json:"totalPods"` Timestamp time.Time `json:"timestamp,omitempty"` } diff --git a/metrics/value/value.go b/metrics/value/value.go index d4eebb0..e8c72e5 100644 --- a/metrics/value/value.go +++ b/metrics/value/value.go @@ -20,5 +20,5 @@ package value // MetricValue is a representation of a computed value for a metric, can be either a raw value or an average value type MetricValue struct { Value *int64 `json:"value,omitempty"` - AverageValue *int64 `json:"average_value,omitempty"` + AverageValue *int64 `json:"averageValue,omitempty"` }