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

Sendconfig update improvements #1397

Merged
merged 8 commits into from
Jun 4, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ released and the release notes may change significantly before then.

#### Under the hood

- the controller manager will no longer log multiple entries for `nil` updates
to the Kong Admin API. The result is that operators will no longer see multiple
"no configuration change, skipping sync to kong" entries for any single update,
instead it will only report this `nil` update scenario the first time it is
encountered for any particular SHA derived from the configuration contents.
- the `--sync-rate-limit` is now deprecated in favor of `--sync-time-seconds`.
This functionality no longer blocks goroutines until the provided number of
seconds has passed to enforce rate limiting, now instead it configures a
Expand Down
4 changes: 4 additions & 0 deletions pkg/sendconfig/common_workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/kong/kubernetes-ingress-controller/pkg/store"
)

// -----------------------------------------------------------------------------
// Sendconfig - Workflow Functions
// -----------------------------------------------------------------------------

// UpdateKongAdminSimple is a helper function for the most common usage of PerformUpdate() with only minimal
// upfront configuration required. This function is specialized and highly opinionated.
//
Expand Down
36 changes: 34 additions & 2 deletions pkg/sendconfig/sendconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"reflect"
"sync"

"github.com/kong/deck/diff"
"github.com/kong/deck/dump"
Expand All @@ -33,7 +34,6 @@ func PerformUpdate(ctx context.Context,
customEntities []byte,
oldSHA []byte,
) ([]byte, error) {

newSHA, err := deckgen.GenerateSHA(targetContent, customEntities)
if err != nil {
return oldSHA, err
Expand All @@ -42,7 +42,9 @@ func PerformUpdate(ctx context.Context,
if !reverseSync {
// use the previous SHA to determine whether or not to perform an update
if equalSHA(oldSHA, newSHA) {
log.Info("no configuration change, skipping sync to kong")
if !hasSHAUpdateAlreadyBeenReported(newSHA) {
log.Info("no configuration change, skipping sync to kong")
}
return oldSHA, nil
}
}
Expand Down Expand Up @@ -186,3 +188,33 @@ func onUpdateDBMode(ctx context.Context,
}
return nil
}

// -----------------------------------------------------------------------------
// Sendconfig - Logging & Reporting Helper Functions
// -----------------------------------------------------------------------------

var (
latestReportedSHA []byte
shaLock sync.RWMutex
)

// hasSHAUpdateAlreadyBeenReported is a helper function to allow
// sendconfig internals to be aware of the last logged/reported
// update to the Kong Admin API. Given the most recent update SHA,
// it will return true/false whether or not that SHA has previously
// been reported (logged, e.t.c.) so that the caller can make
// decisions (such as staggering or stifling duplicate log lines).
//
// TODO: This is a bit of a hack for now to keep backwards compat,
// but in the future we might configure rolling this into
// some object/interface which has this functionality as an
// inherent behavior.
func hasSHAUpdateAlreadyBeenReported(latestUpdateSHA []byte) bool {
shaLock.Lock()
defer shaLock.Unlock()
if equalSHA(latestReportedSHA, latestUpdateSHA) {
return true
}
latestReportedSHA = latestUpdateSHA
return false
}
12 changes: 12 additions & 0 deletions pkg/sendconfig/sendconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/kong/deck/file"
"github.com/kong/go-kong/kong"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func Test_renderConfigWithCustomEntities(t *testing.T) {
Expand Down Expand Up @@ -116,3 +117,14 @@ func Test_renderConfigWithCustomEntities(t *testing.T) {
})
}
}

func Test_updateReportingUtilities(t *testing.T) {
shaneutt marked this conversation as resolved.
Show resolved Hide resolved
assert.False(t, hasSHAUpdateAlreadyBeenReported([]byte("fake-sha")))
assert.True(t, hasSHAUpdateAlreadyBeenReported([]byte("fake-sha")))
assert.False(t, hasSHAUpdateAlreadyBeenReported([]byte("another-fake-sha")))
assert.True(t, hasSHAUpdateAlreadyBeenReported([]byte("another-fake-sha")))
assert.False(t, hasSHAUpdateAlreadyBeenReported([]byte("yet-another-fake-sha")))
assert.True(t, hasSHAUpdateAlreadyBeenReported([]byte("yet-another-fake-sha")))
assert.True(t, hasSHAUpdateAlreadyBeenReported([]byte("yet-another-fake-sha")))
assert.True(t, hasSHAUpdateAlreadyBeenReported([]byte("yet-another-fake-sha")))
}
8 changes: 6 additions & 2 deletions railgun/internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ import (
const (
// DefaultSyncSeconds indicates the time.Duration (minimum) that will occur between
// updates to the Kong Proxy Admin API when using the NewProxy() constructor.
// this 1s default was based on local testing wherein it appeared sub-second updates
// to the Admin API could be problematic (or at least operate differently) based on
// which storage backend was in use (i.e. "dbless", "postgres"). This is a workaround
// for improvements we still need to investigate upstream.
//
// NOTE: this default was originally inherited from KIC v1.x.
DefaultSyncSeconds float32 = 0.3
// See Also: https://github.com/Kong/kubernetes-ingress-controller/issues/1398
DefaultSyncSeconds float32 = 1.0
shaneutt marked this conversation as resolved.
Show resolved Hide resolved

// DefaultObjectBufferSize is the number of client.Objects that the server will buffer
// before it starts rejecting new objects while it processes the originals.
Expand Down
2 changes: 1 addition & 1 deletion railgun/test/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
waitTick = time.Second * 1

// ingressWait is the default amount of time to wait for any particular ingress resource to be provisioned.
ingressWait = time.Minute * 5
ingressWait = time.Minute * 3

// httpcTimeout is the default client timeout for HTTP clients used in tests.
httpcTimeout = time.Second * 3
Expand Down