gitlab-rspec-metrics-exporter

An RSpec formatter that collects test execution data and pushes it to the GitLab Quality Observer service.

Installation

Add it to your Gemfile:

group :test do
  gem "gitlab-rspec-metrics-exporter"
end

Usage

Configuration helper

Preferred way to configure the formatter is to use ConfigHelper class:

require "gitlab/rspec-metrics-exporter"

Gitlab::RSpecMetricsExporter::ConfigHelper.configure!("backend_unit")

You may pass a block to further customize the exporter:

Gitlab::RSpecMetricsExporter::ConfigHelper.configure!("backend_unit") do |config|
  config. = [:smoke, :reliable]
  config.skip_record_proc = ->(example) { example.[:do_not_export] }
end

Configuration options

When the ConfigHelper.configure! helper is used, the options marked with an Env var below are populated automatically from the environment. All options can also be set explicitly via yielded config object; explicit values always take precedence over the corresponding environment variable.

Option Env var Description
observer_url GLCI_OBSERVER_URL Observer service base URL
observer_token GLCI_OBSERVER_AUTH_TOKEN Auth token sent as X-Gitlab-Token
run_type GLCI_TEST_METRICS_RUN_TYPE Suite name (falls back to CI_JOB_NAME or "unknown")
extra_rspec_metadata_keys (none) Additional example.metadata keys to include in metrics
spec_file_path_prefix (none) Prepended to file paths (useful for monorepos)
skip_record_proc (none) Lambda receiving an example; return true to skip exporting
test_retried_proc (none) Lambda receiving an example; return true if it was a retry
custom_metrics_proc (none) Lambda returning a hash merged into every metric record
logger (none) Ruby Logger instance

The config helper also reads two control-flow variables that gate whether the exporter activates at all:

Variable Purpose
CI Must be set (any non-empty value) for the helper to run
GLCI_EXPORT_TEST_METRICS Set to "false" to disable export. Defaults to "true".

Development

bundle install
bundle exec rspec

Release

Create merge request with version update in version.rb file

License

MIT.