<commit_before>package symptom

import (
	"time"

	"github.com/mefellows/muxy/log"
	"github.com/mefellows/muxy/muxy"
	"github.com/mefellows/plugo/plugo"
)

// HTTPDelaySymptom adds specified delays to HTTP requests
// Update docs: these values should be in ms
type HTTPDelaySymptom struct {
	RequestDelay  int `required:"false" mapstructure:"request_delay"`
	ResponseDelay int `required:"false" mapstructure:"response_delay"`
	Delay         int `required:"false" mapstructure:"delay"`
}

func init() {
	plugo.PluginFactories.Register(func() (interface{}, error) {
		return &HTTPDelaySymptom{}, nil
	}, "http_delay")
	plugo.PluginFactories.Register(func() (interface{}, error) {
		return &HTTPDelaySymptom{}, nil
	}, "delay")
}

// Setup sets up the delay plugin
func (m HTTPDelaySymptom) Setup() {
	log.Debug("HTTP Delay Setup()")
}

// Teardown shuts down the plugin
func (m HTTPDelaySymptom) Teardown() {
	log.Debug("HTTP Delay Teardown()")
}

// HandleEvent takes a proxy event for the proxy to intercept and modify
func (m HTTPDelaySymptom) HandleEvent(e muxy.ProxyEvent, ctx *muxy.Context) {
	switch e {
	case muxy.EventPreDispatch:
		if m.RequestDelay != 0 {
			m.Muck(ctx, m.RequestDelay)
		}
	case muxy.EventPostDispatch:
		if m.ResponseDelay != 0 {
			m.Muck(ctx, m.ResponseDelay)
		} else if m.Delay != 0 { // legacy behaviour
			m.Muck(ctx, m.Delay*1000) // convert to ms
		}
	}
}

// Muck injects chaos into the system
func (m *HTTPDelaySymptom) Muck(ctx *muxy.Context, wait int) {
	delay := time.Duration(wait) * time.Millisecond
	log.Debug("HTTP Delay Muck(), delaying for %v seconds\n", delay.Seconds())

	for {
		select {
		case <-time.After(delay):
			return
		}
	}
}<commit_msg>chore(formatting): update log formatting in delay symptom<commit_after>package symptom

import (
	"time"

	"github.com/mefellows/muxy/log"
	"github.com/mefellows/muxy/muxy"
	"github.com/mefellows/plugo/plugo"
)

// HTTPDelaySymptom adds specified delays to requests Symptom
// Update docs: these values should be in ms
type HTTPDelaySymptom struct {
	RequestDelay  int `required:"false" mapstructure:"request_delay"`
	ResponseDelay int `required:"false" mapstructure:"response_delay"`
	Delay         int `required:"false" mapstructure:"delay"`
}

func init() {
	plugo.PluginFactories.Register(func() (interface{}, error) {
		return &HTTPDelaySymptom{}, nil
	}, "http_delay")
	plugo.PluginFactories.Register(func() (interface{}, error) {
		return &HTTPDelaySymptom{}, nil
	}, "delay")
}

// Setup sets up the delay plugin
func (m HTTPDelaySymptom) Setup() {
	log.Debug("Delay Symptom - Setup()")
}

// Teardown shuts down the plugin
func (m HTTPDelaySymptom) Teardown() {
	log.Debug("Delay Symptom - Teardown()")
}

// HandleEvent takes a proxy event for the proxy to intercept and modify
func (m HTTPDelaySymptom) HandleEvent(e muxy.ProxyEvent, ctx *muxy.Context) {
	switch e {
	case muxy.EventPreDispatch:
		if m.RequestDelay != 0 {
			m.Muck(ctx, m.RequestDelay)
		}
	case muxy.EventPostDispatch:
		if m.ResponseDelay != 0 {
			m.Muck(ctx, m.ResponseDelay)
		} else if m.Delay != 0 { // legacy behaviour
			m.Muck(ctx, m.Delay*1000) // convert to ms
		}
	}
}

// Muck injects chaos into the system
func (m *HTTPDelaySymptom) Muck(ctx *muxy.Context, wait int) {
	delay := time.Duration(wait) * time.Millisecond
	log.Debug("Delay Symptom - Muck(), delaying for %v seconds", delay.Seconds())

	for {
		select {
		case <-time.After(delay):
			return
		}
	}
}
{'fraction_non_alphanumeric': 0.1323870220162225, 'fraction_numerical': 0.004055619930475087, 'mean_word_length': 4.279816513761468, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '77453', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1236, 'n_words': 312}