From e552beab2e53ca7dbca25252491b253997b22d4f Mon Sep 17 00:00:00 2001 From: Joseph Patrick Copenhaver Date: Sat, 11 Nov 2023 22:20:29 -0600 Subject: [PATCH] simplify option names and logic for v3 --- docs/metrics.md | 44 ++++++++++---------- loadtester/example/main.go | 3 +- loadtester/example_http/main.go | 3 +- loadtester/gen_strategies.go | 8 ++-- loadtester/internal/cmd/generate/run.go.tmpl | 2 +- loadtester/loadtest.go | 16 +++---- loadtester/loadtest_options.go | 17 ++++---- 7 files changed, 48 insertions(+), 45 deletions(-) diff --git a/docs/metrics.md b/docs/metrics.md index 3e6076c..fac5cd2 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -19,28 +19,28 @@ The output CSV file has the following metric possibilities: | min_task_latency | Duration String | The smallest duration a task spent in the execution phase for tasks completed in the sample interval. | | avg_task_latency | Duration String | The average duration a task spent in the execution phase for tasks completed in the sample interval. | | max_task_latency | Duration String | The largest duration a task spent in the execution phase for tasks completed in the sample interval. | -| p25_queue_latency | RFC3339Nano Time String \| empty string | 25% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p50_queue_latency | RFC3339Nano Time String \| empty string | 50% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p75_queue_latency | RFC3339Nano Time String \| empty string | 75% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p80_queue_latency | RFC3339Nano Time String \| empty string | 80% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p85_queue_latency | RFC3339Nano Time String \| empty string | 85% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p90_queue_latency | RFC3339Nano Time String \| empty string | 90% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p95_queue_latency | RFC3339Nano Time String \| empty string | 95% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p99_queue_latency | RFC3339Nano Time String \| empty string | 99% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p99p9_queue_latency | RFC3339Nano Time String \| empty string | 99.90% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p99p99_queue_latency | RFC3339Nano Time String \| empty string | 99.99% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p25_task_latency | RFC3339Nano Time String \| empty string | 25% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p50_task_latency | RFC3339Nano Time String \| empty string | 50% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p75_task_latency | RFC3339Nano Time String \| empty string | 75% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p80_task_latency | RFC3339Nano Time String \| empty string | 80% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p85_task_latency | RFC3339Nano Time String \| empty string | 85% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p90_task_latency | RFC3339Nano Time String \| empty string | 90% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p95_task_latency | RFC3339Nano Time String \| empty string | 95% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p99_task_latency | RFC3339Nano Time String \| empty string | 99% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p99p9_task_latency | RFC3339Nano Time String \| empty string | 99.90% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| p99p99_task_latency | RFC3339Nano Time String \| empty string | 99.99% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentilesEnabled() option is set to true ( default value: false) | -| queue_latency_variance | Duration String \| empty string | The welford variance value computed for the queue phase of tasks completed in the sample interval. Always output in nanoseconds. Will be set to an empty string if the sample size for the interval is less than two. Only present in output file when the MetricsLatencyVariancesEnabled() option is set to true ( default value: false) | -| task_latency_variance | Duration String \| empty string | The welford variance value computed for the execution phase of tasks completed in the sample interval. Always output in nanoseconds. Will be set to an empty string if the sample size for the interval is less than two. Only present in output file when the MetricsLatencyVariancesEnabled() option is set to true ( default value: false) | +| p25_queue_latency | RFC3339Nano Time String \| empty string | 25% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p50_queue_latency | RFC3339Nano Time String \| empty string | 50% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p75_queue_latency | RFC3339Nano Time String \| empty string | 75% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p80_queue_latency | RFC3339Nano Time String \| empty string | 80% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p85_queue_latency | RFC3339Nano Time String \| empty string | 85% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p90_queue_latency | RFC3339Nano Time String \| empty string | 90% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p95_queue_latency | RFC3339Nano Time String \| empty string | 95% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p99_queue_latency | RFC3339Nano Time String \| empty string | 99% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p99p9_queue_latency | RFC3339Nano Time String \| empty string | 99.90% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p99p99_queue_latency | RFC3339Nano Time String \| empty string | 99.99% of all metric records in the sample interval have a queue phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p25_task_latency | RFC3339Nano Time String \| empty string | 25% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p50_task_latency | RFC3339Nano Time String \| empty string | 50% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p75_task_latency | RFC3339Nano Time String \| empty string | 75% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p80_task_latency | RFC3339Nano Time String \| empty string | 80% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p85_task_latency | RFC3339Nano Time String \| empty string | 85% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p90_task_latency | RFC3339Nano Time String \| empty string | 90% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p95_task_latency | RFC3339Nano Time String \| empty string | 95% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p99_task_latency | RFC3339Nano Time String \| empty string | 99% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p99p9_task_latency | RFC3339Nano Time String \| empty string | 99.90% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| p99p99_task_latency | RFC3339Nano Time String \| empty string | 99.99% of all metric records in the sample interval have an execution phase latency at or under this value. It will be an empty string if there are no records in the sample interval. Only present in output file when the MetricsLatencyPercentile() option is set to true ( default value: false) | +| queue_latency_variance | Duration String \| empty string | The welford variance value computed for the queue phase of tasks completed in the sample interval. Always output in nanoseconds. Will be set to an empty string if the sample size for the interval is less than two. Only present in output file when the MetricsLatencyVariance() option is set to true ( default value: false) | +| task_latency_variance | Duration String \| empty string | The welford variance value computed for the execution phase of tasks completed in the sample interval. Always output in nanoseconds. Will be set to an empty string if the sample size for the interval is less than two. Only present in output file when the MetricsLatencyVariance() option is set to true ( default value: false) | | percent_done | Double | A numeric value with precision to the second decimal place ranging from 0 to 100. Only present in output file when the MaxTasks() option is set to a value greater than zero ( default value: 0) | # changelog diff --git a/loadtester/example/main.go b/loadtester/example/main.go index bbd5131..a1bce02 100644 --- a/loadtester/example/main.go +++ b/loadtester/example/main.go @@ -77,9 +77,10 @@ func main() { op.NumIntervalTasks(25), op.Interval(1*time.Second), op.Retry(false), // default is true; not required for this example since no tasks can be retried, plus saves some minor compute and disk io - // op.MetricsLatencyPercentilesEnabled(true), // default is false + // op.MetricsLatencyPercentile(true), // default is false // op.MetricsLatencyVarianceEnabled(true), // default is false // op.FlushRetriesOnShutdown(true), // default is false + // op.MetricsCsv(false) // default is true; set to false to stop creating a metrics.csv file on loadtest run ) if err != nil { panic(err) diff --git a/loadtester/example_http/main.go b/loadtester/example_http/main.go index 7764a3d..ddbe874 100644 --- a/loadtester/example_http/main.go +++ b/loadtester/example_http/main.go @@ -146,9 +146,10 @@ func main() { op.NumIntervalTasks(parallelism), op.Interval(5*time.Second), op.Retry(false), // default is true; not required for this example since no tasks can be retried, plus saves some minor compute and disk io - // op.MetricsLatencyPercentilesEnabled(true), // default is false + // op.MetricsLatencyPercentile(true), // default is false // op.MetricsLatencyVarianceEnabled(true), // default is false // op.FlushRetriesOnShutdown(true), // default is false + // op.MetricsCsv(false) // default is true; set to false to stop creating a metrics.csv file on loadtest run ) if err != nil { panic(err) diff --git a/loadtester/gen_strategies.go b/loadtester/gen_strategies.go index 46d747f..d53c448 100644 --- a/loadtester/gen_strategies.go +++ b/loadtester/gen_strategies.go @@ -802,7 +802,7 @@ func (lt *Loadtest) run_retriesEnabled_maxTasksGTZero_metricsEnabled(ctx context lt.startTime = time.Now() - // if lt.csvData.writeErr == nil // a.k.a. !cfg.csvOutputDisabled // (a.k.a. metrics enabled) + // if lt.csvData.writeErr == nil // a.k.a. cfg.csvOutputEnabled // (a.k.a. metrics enabled) { csvFile, err := os.Create(lt.csvData.outputFilename) @@ -2314,7 +2314,7 @@ func (lt *Loadtest) run_retriesEnabled_maxTasksNotGTZero_metricsEnabled(ctx cont lt.startTime = time.Now() - // if lt.csvData.writeErr == nil // a.k.a. !cfg.csvOutputDisabled // (a.k.a. metrics enabled) + // if lt.csvData.writeErr == nil // a.k.a. cfg.csvOutputEnabled // (a.k.a. metrics enabled) { csvFile, err := os.Create(lt.csvData.outputFilename) @@ -3720,7 +3720,7 @@ func (lt *Loadtest) run_retriesDisabled_maxTasksGTZero_metricsEnabled(ctx contex lt.startTime = time.Now() - // if lt.csvData.writeErr == nil // a.k.a. !cfg.csvOutputDisabled // (a.k.a. metrics enabled) + // if lt.csvData.writeErr == nil // a.k.a. cfg.csvOutputEnabled // (a.k.a. metrics enabled) { csvFile, err := os.Create(lt.csvData.outputFilename) @@ -4666,7 +4666,7 @@ func (lt *Loadtest) run_retriesDisabled_maxTasksNotGTZero_metricsEnabled(ctx con lt.startTime = time.Now() - // if lt.csvData.writeErr == nil // a.k.a. !cfg.csvOutputDisabled // (a.k.a. metrics enabled) + // if lt.csvData.writeErr == nil // a.k.a. cfg.csvOutputEnabled // (a.k.a. metrics enabled) { csvFile, err := os.Create(lt.csvData.outputFilename) diff --git a/loadtester/internal/cmd/generate/run.go.tmpl b/loadtester/internal/cmd/generate/run.go.tmpl index 6ab47a2..b4b77a6 100644 --- a/loadtester/internal/cmd/generate/run.go.tmpl +++ b/loadtester/internal/cmd/generate/run.go.tmpl @@ -6,7 +6,7 @@ func (lt *Loadtest) run_retries{{if .RetriesEnabled}}Enabled{{else}}Disabled{{en lt.startTime = time.Now() {{if .MetricsEnabled}} - // if lt.csvData.writeErr == nil // a.k.a. !cfg.csvOutputDisabled // (a.k.a. metrics enabled) + // if lt.csvData.writeErr == nil // a.k.a. cfg.csvOutputEnabled // (a.k.a. metrics enabled) { csvFile, err := os.Create(lt.csvData.outputFilename) diff --git a/loadtester/loadtest.go b/loadtester/loadtest.go index f5a38eb..7091447 100644 --- a/loadtester/loadtest.go +++ b/loadtester/loadtest.go @@ -122,7 +122,7 @@ func NewLoadtest(options ...LoadtestOption) (*Loadtest, error) { // config buffers var resultsChan chan taskResult - if !cfg.csvOutputDisabled { + if cfg.csvOutputEnabled { resultsChan = make(chan taskResult, cfg.resultsChanSize) } @@ -177,42 +177,42 @@ func NewLoadtest(options ...LoadtestOption) (*Loadtest, error) { retry: cfg.retry, logger: cfg.logger, intervalTasksSema: sm, - metricsEnabled: !cfg.csvOutputDisabled, + metricsEnabled: cfg.csvOutputEnabled, percentilesEnabled: cfg.percentilesEnabled, latencies: latencies, variancesEnabled: cfg.variancesEnabled, } if cfg.retry { - if !cfg.csvOutputDisabled { + if cfg.csvOutputEnabled { lt.doTask = lt.doTask_retriesEnabled_metricsEnabled } else { lt.doTask = lt.doTask_retriesEnabled_metricsDisabled } if cfg.maxTasks > 0 { - if !cfg.csvOutputDisabled { + if cfg.csvOutputEnabled { lt.run = lt.run_retriesEnabled_maxTasksGTZero_metricsEnabled } else { lt.run = lt.run_retriesEnabled_maxTasksGTZero_metricsDisabled } - } else if !cfg.csvOutputDisabled { + } else if cfg.csvOutputEnabled { lt.run = lt.run_retriesEnabled_maxTasksNotGTZero_metricsEnabled } else { lt.run = lt.run_retriesEnabled_maxTasksNotGTZero_metricsDisabled } } else { - if !cfg.csvOutputDisabled { + if cfg.csvOutputEnabled { lt.doTask = lt.doTask_retriesDisabled_metricsEnabled } else { lt.doTask = lt.doTask_retriesDisabled_metricsDisabled } if cfg.maxTasks > 0 { - if !cfg.csvOutputDisabled { + if cfg.csvOutputEnabled { lt.run = lt.run_retriesDisabled_maxTasksGTZero_metricsEnabled } else { lt.run = lt.run_retriesDisabled_maxTasksGTZero_metricsDisabled } - } else if !cfg.csvOutputDisabled { + } else if cfg.csvOutputEnabled { lt.run = lt.run_retriesDisabled_maxTasksNotGTZero_metricsEnabled } else { lt.run = lt.run_retriesDisabled_maxTasksNotGTZero_metricsDisabled diff --git a/loadtester/loadtest_options.go b/loadtester/loadtest_options.go index 2c46a81..2881866 100644 --- a/loadtester/loadtest_options.go +++ b/loadtester/loadtest_options.go @@ -30,7 +30,7 @@ type loadtestConfig struct { interval time.Duration csvOutputFilename string csvOutputFlushInterval time.Duration - csvOutputDisabled bool + csvOutputEnabled bool flushRetriesTimeout time.Duration flushRetriesOnShutdown bool retry bool @@ -50,6 +50,7 @@ func newLoadtestConfig(options ...LoadtestOption) (loadtestConfig, error) { maxIntervalTasks: 1, numIntervalTasks: 1, interval: time.Second, + csvOutputEnabled: true, csvOutputFilename: "metrics.csv", csvOutputFlushInterval: 5 * time.Second, retry: true, @@ -117,7 +118,7 @@ func newLoadtestConfig(options ...LoadtestOption) (loadtestConfig, error) { } // check for integer overflows from user input when computing metrics - if !cfg.csvOutputDisabled { + if cfg.csvOutputEnabled { const intervalPossibleLagResultCount = 1 // note: if intervalPossibleLagResultCount is ever adjusted, then the bellow if statement needs to change if cfg.maxIntervalTasks == math.MaxInt { @@ -227,25 +228,25 @@ func (newOpts) MetricsCsvFlushInterval(d time.Duration) LoadtestOption { } } -func (newOpts) MetricsCsvWriterDisabled(b bool) LoadtestOption { +func (newOpts) MetricsCsv(b bool) LoadtestOption { return func(cfg *loadtestConfig) { - cfg.csvOutputDisabled = b + cfg.csvOutputEnabled = b } } -// MetricsLatencyPercentilesEnabled can greatly increase the amount of memory used +// MetricsLatencyPercentile can greatly increase the amount of memory used // and create additional delay while processing results. // // Make sure MaxIntervalTasks is either not set or if it must be set make // sure it is not too large for the hosts's ram availability. -func (newOpts) MetricsLatencyPercentilesEnabled(b bool) LoadtestOption { +func (newOpts) MetricsLatencyPercentile(b bool) LoadtestOption { return func(cfg *loadtestConfig) { cfg.percentilesEnabled = b } } -// MetricsLatencyVariancesEnabled can create additional delay while processing results. -func (newOpts) MetricsLatencyVariancesEnabled(b bool) LoadtestOption { +// MetricsLatencyVariance can create additional delay while processing results. +func (newOpts) MetricsLatencyVariance(b bool) LoadtestOption { return func(cfg *loadtestConfig) { cfg.variancesEnabled = b }