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

Fix: Limit the number of events and minify the events #4402

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
helm repo add localstack-repo http://helm.localstack.cloud
helm upgrade --install localstack localstack-repo/localstack --version 0.1.2
pip install awscli
kubectl wait --timeout=60s --for=condition=ready --all pod
kubectl wait --timeout=160s --for=condition=ready --all pod

- name: Run integration test
run: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ For more information and how-to, see [RFC: Keep A Changelog](https://github.com/
- Fix daemon-server `SetDNSServer` endpoint to validate provided server address [#4246](https://github.com/chaos-mesh/chaos-mesh/pull/4246)
- Enable prometheus directive within CoreDNS [#4321](https://github.com/chaos-mesh/chaos-mesh/pull/4321)
- Fix TTL configuration from environment variables [#4338](https://github.com/chaos-mesh/chaos-mesh/pull/4338)
- Fix limit the number of events and minify the events [#4402](https://github.com/chaos-mesh/chaos-mesh/pull/4402)

### Security

Expand Down
13 changes: 13 additions & 0 deletions controllers/common/records/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
"github.com/chaos-mesh/chaos-mesh/controllers/chaosimpl/types"
"github.com/chaos-mesh/chaos-mesh/controllers/config"
"github.com/chaos-mesh/chaos-mesh/controllers/utils/recorder"
"github.com/chaos-mesh/chaos-mesh/pkg/selector"
)
Expand Down Expand Up @@ -158,6 +159,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
// but the retry shouldn't block other resource process
idLogger.Error(err, "fail to apply chaos")
applyFailedEvent := newRecordEvent(v1alpha1.TypeFailed, v1alpha1.Apply, err.Error())
if len(records[index].Events) >= config.ControllerCfg.MaxEvents {
records[index].Events = records[index].Events[1:]
}
records[index].Events = append(records[index].Events, *applyFailedEvent)
r.Recorder.Event(obj, recorder.Failed{
Activity: "apply chaos",
Expand All @@ -172,6 +176,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
if record.Phase == v1alpha1.Injected {
records[index].InjectedCount++
applySucceedEvent := newRecordEvent(v1alpha1.TypeSucceeded, v1alpha1.Apply, "")
if len(records[index].Events) >= config.ControllerCfg.MaxEvents {
records[index].Events = records[index].Events[1:]
}
records[index].Events = append(records[index].Events, *applySucceedEvent)
r.Recorder.Event(obj, recorder.Applied{
Id: records[index].Id,
Expand All @@ -188,6 +195,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
// but the retry shouldn't block other resource process
idLogger.Error(err, "fail to recover chaos")
recoverFailedEvent := newRecordEvent(v1alpha1.TypeFailed, v1alpha1.Recover, err.Error())
if len(records[index].Events) >= config.ControllerCfg.MaxEvents {
records[index].Events = records[index].Events[1:]
}
records[index].Events = append(records[index].Events, *recoverFailedEvent)
r.Recorder.Event(obj, recorder.Failed{
Activity: "recover chaos",
Expand All @@ -202,6 +212,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
if record.Phase == v1alpha1.NotInjected {
records[index].RecoveredCount++
recoverSucceedEvent := newRecordEvent(v1alpha1.TypeSucceeded, v1alpha1.Recover, "")
if len(records[index].Events) >= config.ControllerCfg.MaxEvents {
records[index].Events = records[index].Events[1:]
}
records[index].Events = append(records[index].Events, *recoverSucceedEvent)
r.Recorder.Event(obj, recorder.Recovered{
Id: records[index].Id,
Expand Down
2 changes: 1 addition & 1 deletion controllers/utils/chaosdaemon/chaosdaemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (b *ChaosDaemonClientBuilder) FindDaemonIP(ctx context.Context, pod *v1.Pod

daemonIP := findIPOnEndpoints(&endpoints, nodeName)
if len(daemonIP) == 0 {
return "", errors.Errorf("cannot find daemonIP on node %s in related Endpoints %v", nodeName, endpoints)
return "", errors.Errorf("cannot find daemonIP on node %s ", nodeName)
}

return daemonIP, nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ type ChaosControllerConfig struct {
EnabledWebhooks []string `envconfig:"ENABLED_WEBHOOKS" default:"*"`

LocalHelmChartPath string `envconfig:"LOCAL_HELM_CHART_PATH" default:""`

MaxEvents int `envconfig:"MAX_EVENTS" default:"100"`
}

// EnvironChaosController returns the settings from the environment.
Expand Down