xk6-disruptor
xk6-disruptor copied to clipboard
Redesign JavaScript Fault injection API
The xk6-disruptor API is built around the concept of disruptors that inject faults. Presently, each disruptor implements one method for each type of fault it injects and different disruptors can implement the same method if they are able to inject the same type of fault. For example, ServiceDisruptor
and PodDisruptor
both implement the InjectHTTPFault
method for injecting HttpFaults.
Regarding the documentation, having the same method implemented by multiple disruptors introduces redundancy in the documentation, as the description of the method signature and parameters are the same. There may be some minor differences, as noticed above in the case of how the PodDisruptor
and ServiceDisruptor
handle the port
in the HTTPFault
parameter.
As more fault types and more disruptors are added, this duplicity is expected to grow. For example, both a PodDisruptor
and a NodeDisruptor
can implement an InjectNetworkFault
method for injecting network-level disruptions.
The fault injection API could be simplified using a generic InjectFault
function implemented by all disruptors. This function receives the description of the fault as an object.
Disruptor.injectFault(type, fault, duration, options)
The documentation for each disruptor class must lists which types of faults it supports and document any difference in the way they handle these faults. The fault object is documented separately and this description is shared by all disruptors supporting it.