Files
Ronak NathaniandGitHub d7ba03a966 Improves leader election so that we don't lose events (#153)
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.
2024-02-23 08:26:06 +03:00

34 lines
786 B
Go

package setup
import (
"errors"
"strings"
"github.com/goccy/go-yaml"
"github.com/resmoio/kubernetes-event-exporter/pkg/exporter"
)
func ParseConfigFromBytes(configBytes []byte) (exporter.Config, error) {
var config exporter.Config
err := yaml.Unmarshal(configBytes, &config)
if err != nil {
errMsg := err.Error()
errLines := strings.Split(errMsg, "\n")
if len(errLines) > 0 {
errMsg = errLines[0]
}
for _, line := range errLines {
if strings.Contains(line, "> ") {
errMsg += ": [ line " + line + "]"
if strings.Contains(line, "{{") {
errMsg += ": " + "Need to wrap values with special characters in quotes"
}
}
}
errMsg = "Cannot parse config to YAML: " + errMsg
return exporter.Config{}, errors.New(errMsg)
}
return config, nil
}