mirror of
https://github.com/resmoio/kubernetes-event-exporter.git
synced 2026-08-20 15:26:20 +00:00
Currently, when a replica loses its leadership, a new leader isn't elected until leaseDuration seconds. Here, that is 15s. The max time till we get a new leader is leaseDuration (15s) + retryPeriod (2s) = 17s. This commit updates the shutdown process such that if the leader replica is sent a shutdown signal, it sleeps for leaseDuration seconds. This allows the leader replica to continue to export events until a new leader is elected. And a new leader is elected only if lease hasn't been renewed and leaseDuration expires. In addition to this, leader election now uses the leases object instead of configMaps and leases. The clusterRole is also updated to allow writing to the leases object. For use cases where no event loss is tolerable, users should use maxEventAgeSeconds to > 1.
88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
package setup
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func Test_ParseConfigFromBytes_ExampleConfigIsCorrect(t *testing.T) {
|
|
configBytes, err := os.ReadFile("../../config.example.yaml")
|
|
if err != nil {
|
|
assert.NoError(t, err, "cannot read config file: "+err.Error())
|
|
return
|
|
}
|
|
|
|
config, err := ParseConfigFromBytes(configBytes)
|
|
|
|
assert.NoError(t, err)
|
|
assert.NotEmpty(t, config.LogLevel)
|
|
assert.NotEmpty(t, config.LogFormat)
|
|
assert.NotEmpty(t, config.Route)
|
|
assert.NotEmpty(t, config.Route.Routes)
|
|
assert.Equal(t, 4, len(config.Route.Routes))
|
|
assert.NotEmpty(t, config.Receivers)
|
|
assert.Equal(t, 10, len(config.Receivers))
|
|
}
|
|
|
|
func Test_ParseConfigFromBytes_NoErrors(t *testing.T) {
|
|
configBytes := []byte(`
|
|
logLevel: info
|
|
logFormat: json
|
|
`)
|
|
|
|
config, err := ParseConfigFromBytes(configBytes)
|
|
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "info", config.LogLevel)
|
|
assert.Equal(t, "json", config.LogFormat)
|
|
}
|
|
|
|
func Test_ParseConfigFromBytes_ErrorWhenCurlyBracesNotEscaped(t *testing.T) {
|
|
configBytes := []byte(`
|
|
logLevel: {{info}}
|
|
logFormat: json
|
|
`)
|
|
|
|
config, err := ParseConfigFromBytes(configBytes)
|
|
|
|
expectedErrorLine := "> 2 | logLevel: {{info}}"
|
|
expectedErrorSuggestion := "Need to wrap values with special characters in quotes"
|
|
assert.NotNil(t, err)
|
|
assert.Contains(t, err.Error(), expectedErrorLine)
|
|
assert.Contains(t, err.Error(), expectedErrorSuggestion)
|
|
assert.Equal(t, "", config.LogLevel)
|
|
assert.Equal(t, "", config.LogFormat)
|
|
}
|
|
|
|
func Test_ParseConfigFromBytes_OkWhenCurlyBracesEscaped(t *testing.T) {
|
|
configBytes := []byte(`
|
|
logLevel: "{{info}}"
|
|
logFormat: json
|
|
`)
|
|
|
|
config, err := ParseConfigFromBytes(configBytes)
|
|
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "{{info}}", config.LogLevel)
|
|
assert.Equal(t, "json", config.LogFormat)
|
|
}
|
|
|
|
func Test_ParseConfigFromBytes_ErrorErrorNotWithCurlyBraces(t *testing.T) {
|
|
configBytes := []byte(`
|
|
logLevelNotYAMLErrorError
|
|
logFormat: json
|
|
`)
|
|
|
|
config, err := ParseConfigFromBytes(configBytes)
|
|
|
|
expectedErrorLine := "> 2 | logLevelNotYAMLErrorError"
|
|
expectedErrorSuggestion := "Need to wrap values with special characters in quotes"
|
|
assert.NotNil(t, err)
|
|
assert.Contains(t, err.Error(), expectedErrorLine)
|
|
assert.NotContains(t, err.Error(), expectedErrorSuggestion)
|
|
assert.Equal(t, "", config.LogLevel)
|
|
assert.Equal(t, "", config.LogFormat)
|
|
}
|