## Introduction - It can target random pods with a Spring Boot application and allows configuring the assaults to inject exceptions at runtime when the method is used. It tests the resiliency of the system when some applications are having unexpected faulty behavior. !!! tip "Scenario: Inject exceptions to Spring Boot Application" ![Spring Boot Exceptions](../../images/spring-boot-chaos.png) ## Uses ??? info "View the uses of the experiment" coming soon ## Prerequisites ??? info "Verify the prerequisites" ## Default Validations ??? info "View the default validations" - Spring boot pods are healthy before and after chaos injection ## Minimal RBAC configuration example (optional) !!! tip "NOTE" If you are using this experiment as part of a litmus workflow scheduled constructed & executed from chaos-center, then you may be making use of the [litmus-admin](https://litmuschaos.github.io/litmus/litmus-admin-rbac.yaml) RBAC, which is pre-installed in the cluster as part of the agent setup. ??? note "View the Minimal RBAC permissions" ```yaml apiVersion: v1 kind: ServiceAccount metadata: name: spring-boot-exceptions-sa namespace: default labels: name: spring-boot-exceptions-sa app.kubernetes.io/part-of: litmus --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: spring-boot-exceptions-sa namespace: default labels: name: spring-boot-exceptions-sa app.kubernetes.io/part-of: litmus rules: # Create and monitor the experiment & helper pods - apiGroups: [""] resources: ["pods"] verbs: ["create","delete","get","list","patch","update", "deletecollection"] # Performs CRUD operations on the events inside chaosengine and chaosresult - apiGroups: [""] resources: ["events"] verbs: ["create","get","list","patch","update"] # Track and get the runner, experiment, and helper pods log - apiGroups: [""] resources: ["pods/log"] verbs: ["get","list","watch"] # for creating and managing to execute commands inside target container - apiGroups: [""] resources: ["pods/exec"] verbs: ["get","list","create"] # for configuring and monitor the experiment job by the chaos-runner pod - apiGroups: ["batch"] resources: ["jobs"] verbs: ["create","list","get","delete","deletecollection"] # for creation, status polling and deletion of litmus chaos resources used within a chaos workflow - apiGroups: ["litmuschaos.io"] resources: ["chaosengines","chaosexperiments","chaosresults"] verbs: ["create","list","get","patch","update","delete"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: spring-boot-exceptions-sa namespace: default labels: name: spring-boot-exceptions-sa app.kubernetes.io/part-of: litmus roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: spring-boot-exceptions-sa subjects: - kind: ServiceAccount name: spring-boot-exceptions-sa namespace: default ``` Use this sample RBAC manifest to create a chaosServiceAccount in the desired (app) namespace. This example consists of the minimum necessary role permissions to execute the experiment. ## Experiment tunables ??? info "check the experiment tunables"

Mandatory Fields

Variables Description Notes
CM_PORT It contains port of the spring boot application

Optional Fields

Variables Description Notes
CM_EXCEPTIONS_TYPE It contains type of raised exception Defaults value: java.lang.IllegalArgumentException
CM_EXCEPTIONS_ARGUMENTS It contains argument of raised exception Defaults value: java.lang.String:custom illegal argument exception
CM_LEVEL It contains number of requests are to be attacked, n value means nth request will be affected Defaults value: 1, it lies in [1,10000] range
CM_WATCHED_CUSTOM_SERVICES It limits watched packages/classes/methods, it contains comma seperated list of fully qualified packages(class and/or method names) ByDefault it is empty list, which means it target all services
CM_WATCHERS It contains comma separated list of watchers from the following watchers list [controller, restController, service, repository, component, webClient] ByDefault it is restController
TOTAL_CHAOS_DURATION The time duration for chaos injection (seconds) Defaults to 30
SEQUENCE It defines sequence of chaos execution for multiple target pods Default value: parallel. Supported: serial, parallel
PODS_AFFECTED_PERC The Percentage of total pods to target Defaults to 0% (corresponds to 1 replica)
LIB The chaos lib used to inject the chaos Defaults to litmus. Supported litmus only
RAMP_TIME Period to wait before and after injection of chaos in sec
## Experiment Examples ### Common Experiment Tunables Refer the [common attributes](../common/common-tunables-for-all-experiments.md) and [Spring Boot specific tunable](spring-boot-experiments-tunables.md) to tune the common tunables for all experiments and spring-boot specific tunables. ### Spring Boot Application Port It tunes the spring-boot application port via `CM_PORT` ENV Use the following example to tune this: [embedmd]:# (./spring-boot-exceptions/target-port.yaml yaml) ```yaml # kill spring-boot target application apiVersion: litmuschaos.io/v1alpha1 kind: ChaosEngine metadata: name: spring-boot-chaos namespace: default spec: appinfo: appns: 'default' applabel: 'app=spring-boot' appkind: 'deployment' # It can be active/stop engineState: 'active' chaosServiceAccount: spring-boot-exceptions-sa experiments: - name: spring-boot-exceptions spec: components: env: # port of the spring boot application - name: CM_PORT value: '8080' ``` ### Exception Type and Arguments Spring boot exception type and arguments can be tuned via `CM_EXCEPTIONS_TYPE` and `CM_EXCEPTIONS_ARGUMENTS` ENV Use the following example to tune this: [embedmd]:# (./spring-boot-exceptions/exception-type-and-args.yaml yaml) ```yaml # provide the exception type and args apiVersion: litmuschaos.io/v1alpha1 kind: ChaosEngine metadata: name: spring-boot-chaos namespace: default spec: appinfo: appns: 'default' applabel: 'app=spring-boot' appkind: 'deployment' # It can be active/stop engineState: 'active' chaosServiceAccount: spring-boot-exceptions-sa experiments: - name: spring-boot-exceptions spec: components: env: # Type of raised exception - name: CM_EXCEPTIONS_TYPE value: 'java.lang.IllegalArgumentException' # Argument of the raised exception - name: CM_EXCEPTIONS_ARGUMENTS value: 'java.lang.String:custom illegal argument exception' # port of the spring boot application - name: CM_PORT value: '8080' ```