Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use gojson to marshal config for SHA #4222

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ Adding a new version? You'll need three changes:
all involved Services, not just Services whose annotation does not match the
first observed value, as that value is not necessarily the desired value.
[#4171](https://github.com/Kong/kubernetes-ingress-controller/pull/4171)
- Use [`gojson`][gojson] for marshalling JSON when generating SHA for config.
This should yield some performance benefits during config preparation and
sending stage (we've observed around 35% reduced time in config marshalling
time but be aware that your mileage may vary).
[#4222](https://github.com/Kong/kubernetes-ingress-controller/pull/4222)

[gojson]: https://github.com/goccy/go-json

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/bombsimon/logrusr/v2 v2.0.1
github.com/deepmap/oapi-codegen v1.13.0
github.com/go-logr/logr v1.2.4
github.com/goccy/go-json v0.10.2
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/jpillora/backoff v1.0.0
Expand Down Expand Up @@ -60,7 +61,6 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-containerregistry v0.13.0 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
Expand Down
4 changes: 2 additions & 2 deletions internal/dataplane/deckgen/deckgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package deckgen

import (
"crypto/sha256"
"encoding/json"
"fmt"

gojson "github.com/goccy/go-json"
"github.com/kong/deck/file"
"github.com/kong/go-kong/kong"
)

// GenerateSHA generates a SHA256 checksum of targetContent, with the purpose
// of change detection.
func GenerateSHA(targetContent *file.Content) ([]byte, error) {
jsonConfig, err := json.Marshal(targetContent)
jsonConfig, err := gojson.Marshal(targetContent)
if err != nil {
return nil, fmt.Errorf("marshaling Kong declarative configuration to JSON: %w", err)
}
Expand Down