Skip to content

Commit

Permalink
Switch JSON serialization to camel case (#17)
Browse files Browse the repository at this point in the history
JSON serialization of fields uses camel case instead of snake case.
  • Loading branch information
jthomperoo authored Apr 20, 2024
1 parent 1b1bfd6 commit 06ba0c8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion metrics/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
2 changes: 1 addition & 1 deletion metrics/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
6 changes: 3 additions & 3 deletions metrics/podmetrics/podmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions metrics/pods/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
10 changes: 5 additions & 5 deletions metrics/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
2 changes: 1 addition & 1 deletion metrics/value/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 06ba0c8

Please sign in to comment.