Skip to content

Resiliency Feature Draft (krknctl)#82

Open
abhinavs1920 wants to merge 15 commits intokrkn-chaos:mainfrom
abhinavs1920:resiliency
Open

Resiliency Feature Draft (krknctl)#82
abhinavs1920 wants to merge 15 commits intokrkn-chaos:mainfrom
abhinavs1920:resiliency

Conversation

@abhinavs1920
Copy link

@abhinavs1920 abhinavs1920 commented Nov 5, 2025

Description

  • Add env variable (krkn-run-mode) in krknctl-input.json.
  • Implement resiliency-config file volume binding in the container.
  • Implement result calculation fetching container's long.

Documentation

  • Is documentation needed for this update?

If checked, a documentation PR must be created and merged in the website repository.

Related Documentation PR (if applicable)

Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
@abhinavs1920
Copy link
Author

Hii @tsebastiani, I have added the env flag for the krkn-mode, let me know if its the right approach?

Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
@abhinavs1920
Copy link
Author

In my last commit I have updated the Scenario struct, and added ResiliencyConfig into it which is essentially will be a String containing the path of that specific scenario resiliency config.

}
},
{
"name": "krkn-run-mode",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately that's the wrong place, this is the dummy scenario containerfile, you have to open a PR in the krkn source repo from where the image is built:

https://github.com/krkn-chaos/krkn/blob/main/containers/krknctl-input.json

…ge Scenario struct to recieve weight and config

Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
var resiliencyWeights []float64
runStartTime := time.Now().UTC()

reportRegex := regexp.MustCompile(`^KRKN_RESILIENCY_REPORT_JSON:(.*)$`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the regex in the config.json as all the other regex and const strings.

// inject resiliency config as env variable if provided (Use Case: Resiliency Config is provided via env variable)
if scenario.ResiliencyConfigPath != "" {
if content, err := os.ReadFile(scenario.ResiliencyConfigPath); err == nil {
env["RESILIENCY_CONFIG"] = string(content)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure that passing the file content as it is will work in any condition? don't you think that serializing the file content in base64 for example might ensure that the file structure (including indentation, spacing quotes etc.) is safely kept?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I should be serializing the file, and I’ll make that update.

For the custom resiliency config, we could mount the entire file via a volume, but if the environment-variable approach I used doesn’t introduce any edge cases, I think the current method should be fine. Let me know if you see any problems with this.

}
}
runEndTime := time.Now().UTC()
_ = runStartTime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of these void initializations?

Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
…dd the env variable

Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
…_ALERTS_YAML_CONTENT, remove ResiliencyConfig from Scenario, serialize ResiliencyConfig YAML file to base64 and inject it as env variable

Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
@abhinavs1920
Copy link
Author

Hi everyone,

Following up on the krkn PR....

Summary of changes:

  • Controller Mode: It runs the krkn containers in "controller" mode so they emit the raw JSON reports to stdout.
  • Aggregation: It scrapes those reports via regex, matches them to the graph node, and applies the weights defined in the scenario file (defaults to 1 if nothing is set).
  • Final Score: It calculates the final, global weighted average and produces the consolidated resiliency-report.json.

In krknctl you have to provide the prometheus url in the env, it will enable the resiliency feature automatically.

Let me know what you think about its working!

cmd/run.go Outdated
return cerr
}
defer file.Close()
mw := io.MultiWriter(os.Stdout, file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhinavs1920 please add a comment here to explain how the thing works because might be confusing. Explain that you're multiplexing a file and stdout to with a multiwriter and that the container stdout and stderr will written in the machine stdout and in the file. Thanks!

if prom, ok := env["PROMETHEUS_URL"]; ok {
promURL = prom
}
env["RESILIENCY_ENABLED_MODE"] = resiliency.ComputeResiliencyMode(promURL, config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add these string constraints like RESILIENCY_ENABLED_MODE KRKN_ALERTS_YAML_CONTENT etc. to the config.


func PrintHumanSummary(report FinalReport) {
if data, err := json.MarshalIndent(report, "", " "); err == nil {
fmt.Printf("Overall Resiliency Report Summary:\n%s\n", string(data))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logs must be lowercased (except for acronyms)

}

// 2. Nested under telemetry.overall_resiliency_report.
type root2 struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not use numbers in types and variable names

cmd/utils.go Outdated
promURL = prom.value
}
mode := resiliency.ComputeResiliencyMode(promURL, cfg)
environment["RESILIENCY_ENABLED_MODE"] = ParsedField{value: mode, secret: false}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RESILIENCY_ENABLED_MODE must be in the config file

cmd/run.go Outdated

if !runDetached {
// capture stdout/stderr to both terminal and a log file for parsing
filename := fmt.Sprintf("%s.log", containerName)
Copy link
Contributor

@tsebastiani tsebastiani Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ The requirement was that in attached mode the krkn output should have been written on a bytes.Buffer, not in a file.

Overall OverallResiliencyReport `json:"overall_resiliency_report"`
} `json:"telemetry"`
}
var r2 root2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use numbers in variables and package aliases

}

// 3. As a map of scenario scores at root with optional aggregate values.
type root3 struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use numbers in variables and package aliases

PassedSlos int `json:"passed_slos"`
TotalSlos int `json:"total_slos"`
}
var r3 root3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use numbers in variables and package aliases

Failed int `json:"failed"`
} `json:"breakdown"`
}
type root4 struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not use numbers in variables and package aliases

Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
…ruct names

Signed-off-by: Abhinav Sharma <abhinavs1920bpl@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants