Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-29 21:10:10 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-29 21:10:10 +0300
commit89d84b76a93353a8b614860c3b3bccc71917aeeb (patch)
tree89363b03a4e6f42f2b2ea610f471772b05ce7c8a
parentf4395ec210a7c5f5ef4069a2a3e51537123c3038 (diff)
Add latest changes from gitlab-org/gitlab@master
-rw-r--r--app/models/commit.rb4
-rw-r--r--changelogs/unreleased/mk-configurable-sampling-intervals.yml5
-rw-r--r--doc/administration/index.md41
-rw-r--r--doc/administration/integration/plantuml.md2
-rw-r--r--doc/administration/monitoring/performance/index.md11
-rw-r--r--doc/development/api_graphql_styleguide.md7
-rw-r--r--doc/development/documentation/feature_flags.md8
-rw-r--r--doc/install/installation.md13
-rw-r--r--lib/gitlab/git/diff_collection.rb2
-rw-r--r--lib/gitlab/metrics/samplers/action_cable_sampler.rb4
-rw-r--r--lib/gitlab/metrics/samplers/base_sampler.rb12
-rw-r--r--lib/gitlab/metrics/samplers/database_sampler.rb2
-rw-r--r--lib/gitlab/metrics/samplers/puma_sampler.rb2
-rw-r--r--lib/gitlab/metrics/samplers/ruby_sampler.rb2
-rw-r--r--lib/gitlab/metrics/samplers/threads_sampler.rb2
-rw-r--r--lib/gitlab/metrics/samplers/unicorn_sampler.rb2
-rw-r--r--spec/lib/gitlab/metrics/samplers/action_cable_sampler_spec.rb10
-rw-r--r--spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb10
-rw-r--r--spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb10
-rw-r--r--spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb12
-rw-r--r--spec/lib/gitlab/metrics/samplers/threads_sampler_spec.rb10
-rw-r--r--spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb2
-rw-r--r--spec/support/shared_examples/metrics/sampler_shared_examples.rb27
23 files changed, 108 insertions, 92 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 562e9c4710f..6c2a818fc12 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -80,7 +80,7 @@ class Commit
def diff_hard_limit_files(project: nil)
if Feature.enabled?(:increased_diff_limits, project)
- 2000
+ 3000
else
1000
end
@@ -88,7 +88,7 @@ class Commit
def diff_hard_limit_lines(project: nil)
if Feature.enabled?(:increased_diff_limits, project)
- 75000
+ 100000
else
50000
end
diff --git a/changelogs/unreleased/mk-configurable-sampling-intervals.yml b/changelogs/unreleased/mk-configurable-sampling-intervals.yml
new file mode 100644
index 00000000000..8292062acda
--- /dev/null
+++ b/changelogs/unreleased/mk-configurable-sampling-intervals.yml
@@ -0,0 +1,5 @@
+---
+title: Sampler intervals can now be configured via env vars
+merge_request: 50625
+author:
+type: other
diff --git a/doc/administration/index.md b/doc/administration/index.md
index 32c0b1b0712..f071fde2faa 100644
--- a/doc/administration/index.md
+++ b/doc/administration/index.md
@@ -33,14 +33,13 @@ Learn how to install, configure, update, and maintain your GitLab instance.
### Installing GitLab
- [Install](../install/README.md): Requirements, directory structures, and installation methods.
- - [Database load balancing](database_load_balancing.md): Distribute database queries among multiple database servers. **(STARTER ONLY)**
- - [Omnibus support for log forwarding](https://docs.gitlab.com/omnibus/settings/logs.html#udp-log-shipping-gitlab-enterprise-edition-only) **(STARTER ONLY)**
+ - [Database load balancing](database_load_balancing.md): Distribute database queries among multiple database servers.
+ - [Omnibus support for log forwarding](https://docs.gitlab.com/omnibus/settings/logs.html#udp-log-shipping-gitlab-enterprise-edition-only).
- [Reference architectures](reference_architectures/index.md): Add additional resources to support more users.
- [Installing GitLab on Amazon Web Services (AWS)](../install/aws/index.md): Set up GitLab on Amazon AWS.
-- [Geo](geo/index.md): Replicate your GitLab instance to other geographic locations as a read-only fully operational version. **(PREMIUM ONLY)**
-- [Disaster Recovery](geo/disaster_recovery/index.md): Quickly fail-over to a different site with minimal effort in a disaster situation. **(PREMIUM ONLY)**
-- [Pivotal Tile](../install/pivotal/index.md): Deploy GitLab as a preconfigured appliance using Ops Manager (BOSH) for Pivotal Cloud Foundry. **(PREMIUM ONLY)**
-- [Add License](../user/admin_area/license.md): Upload a license at install time to unlock features that are in paid tiers of GitLab. **(STARTER ONLY)**
+- [Geo](geo/index.md): Replicate your GitLab instance to other geographic locations as a read-only fully operational version.
+- [Disaster Recovery](geo/disaster_recovery/index.md): Quickly fail-over to a different site with minimal effort in a disaster situation.
+- [Add License](../user/admin_area/license.md): Upload a license at install time to unlock features that are in paid tiers of GitLab.
### Configuring GitLab
@@ -72,11 +71,9 @@ Learn how to install, configure, update, and maintain your GitLab instance.
to GitLab users through the UI.
- [Elasticsearch](../integration/elasticsearch.md): Enable Elasticsearch to
empower Advanced Search. Useful when you deal with a huge amount of data.
- **(STARTER ONLY)**
-- [External Classification Policy Authorization](../user/admin_area/settings/external_authorization.md)
- **(PREMIUM ONLY)**
+- [External Classification Policy Authorization](../user/admin_area/settings/external_authorization.md).
- [Upload a license](../user/admin_area/license.md): Upload a license to unlock
- features that are in paid tiers of GitLab. **(STARTER ONLY)**
+ features that are in paid tiers of GitLab.
- [Admin Area](../user/admin_area/index.md): for self-managed instance-wide
configuration and maintenance.
- [S/MIME Signing](smime_signing_email.md): how to sign all outgoing notification
@@ -90,7 +87,7 @@ Learn how to install, configure, update, and maintain your GitLab instance.
- [Favicon](../user/admin_area/appearance.md#favicon): Change the default favicon to your own logo.
- [Branded login page](../user/admin_area/appearance.md#sign-in--sign-up-pages): Customize the login page with your own logo, title, and description.
- ["New Project" page](../user/admin_area/appearance.md#new-project-pages): Customize the text to be displayed on the page that opens whenever your users create a new project.
-- [Additional custom email text](../user/admin_area/settings/email.md#custom-additional-text): Add additional custom text to emails sent from GitLab. **(PREMIUM ONLY)**
+- [Additional custom email text](../user/admin_area/settings/email.md#custom-additional-text): Add additional custom text to emails sent from GitLab.
### Maintaining GitLab
@@ -127,15 +124,15 @@ Learn how to install, configure, update, and maintain your GitLab instance.
- [Sign-up restrictions](../user/admin_area/settings/sign_up_restrictions.md): block email addresses of specific domains, or whitelist only specific domains.
- [Access restrictions](../user/admin_area/settings/visibility_and_access_controls.md#enabled-git-access-protocols): Define which Git access protocols can be used to talk to GitLab (SSH, HTTP, HTTPS).
- [Authentication and Authorization](auth/README.md): Configure external authentication with LDAP, SAML, CAS, and additional providers.
- - [Sync LDAP](auth/ldap/index.md) **(STARTER ONLY)**
- - [Kerberos authentication](../integration/kerberos.md) **(STARTER ONLY)**
+ - [Sync LDAP](auth/ldap/index.md).
+ - [Kerberos authentication](../integration/kerberos.md).
- See also other [authentication](../topics/authentication/index.md#gitlab-administrators) topics (for example, enforcing 2FA).
-- [Email users](../tools/email.md): Email GitLab users from within GitLab. **(STARTER ONLY)**
+- [Email users](../tools/email.md): Email GitLab users from within GitLab.
- [User Cohorts](../user/admin_area/analytics/user_cohorts.md): Display the monthly cohorts of new users and their activities over time.
- [Audit events](audit_events.md): View the changes made within the GitLab server for:
- - Groups and projects. **(STARTER)**
- - Instances. **(PREMIUM ONLY)**
-- [Auditor users](auditor_users.md): Users with read-only access to all projects, groups, and other resources on the GitLab instance. **(PREMIUM ONLY)**
+ - Groups and projects.
+ - Instances.
+- [Auditor users](auditor_users.md): Users with read-only access to all projects, groups, and other resources on the GitLab instance.
- [Incoming email](incoming_email.md): Configure incoming emails to allow
users to [reply by email](reply_by_email.md), create [issues by email](../user/project/issues/managing_issues.md#new-issue-via-email) and
[merge requests by email](../user/project/merge_requests/creating_merge_requests.md#new-merge-request-by-email), and to enable [Service Desk](../user/project/service_desk.md).
@@ -143,7 +140,7 @@ Learn how to install, configure, update, and maintain your GitLab instance.
basic Postfix mail server with IMAP authentication on Ubuntu for incoming
emails.
- [Abuse reports](../user/admin_area/abuse_reports.md): View and resolve abuse reports from your users.
-- [Credentials Inventory](../user/admin_area/credentials_inventory.md): With Credentials inventory, GitLab administrators can keep track of the credentials used by their users in their GitLab self-managed instance. **(ULTIMATE ONLY)**
+- [Credentials Inventory](../user/admin_area/credentials_inventory.md): With Credentials inventory, GitLab administrators can keep track of the credentials used by their users in their GitLab self-managed instance.
## Project settings
@@ -151,7 +148,7 @@ Learn how to install, configure, update, and maintain your GitLab instance.
- [Gitaly](gitaly/index.md): Configuring Gitaly, the Git repository storage service for GitLab.
- [Default labels](../user/admin_area/labels.md): Create labels that are automatically added to every new project.
- [Restrict the use of public or internal projects](../public_access/public_access.md#restricting-the-use-of-public-or-internal-projects): Restrict the use of visibility levels for users when they create a project or a snippet.
-- [Custom project templates](../user/admin_area/custom_project_templates.md): Configure a set of projects to be used as custom templates when creating a new project. **(PREMIUM ONLY)**
+- [Custom project templates](../user/admin_area/custom_project_templates.md): Configure a set of projects to be used as custom templates when creating a new project.
## Package Registry administration
@@ -165,7 +162,7 @@ Learn how to install, configure, update, and maintain your GitLab instance.
- [Repository storage paths](repository_storage_paths.md): Manage the paths used to store repositories.
- [Repository storage types](repository_storage_types.md): Information about the different repository storage types.
- [Repository storage Rake tasks](raketasks/storage.md): A collection of Rake tasks to list and migrate existing projects and attachments associated with it from Legacy storage to Hashed storage.
-- [Limit repository size](../user/admin_area/settings/account_and_limit_settings.md): Set a hard limit for your repositories' size. **(STARTER ONLY)**
+- [Limit repository size](../user/admin_area/settings/account_and_limit_settings.md): Set a hard limit for your repositories' size.
- [Static objects external storage](static_objects_external_storage.md): Set external storage for static objects in a repository.
## Continuous Integration settings
@@ -176,7 +173,7 @@ Learn how to install, configure, update, and maintain your GitLab instance.
- [Job artifacts](job_artifacts.md): Enable, disable, and configure job artifacts (a set of files and directories which are outputted by a job when it completes successfully).
- [Job logs](job_logs.md): Information about the job logs.
- [Register runners](../ci/runners/README.md#types-of-runners): Learn how to register and configure runners.
-- [Shared runners pipelines quota](../user/admin_area/settings/continuous_integration.md#shared-runners-pipeline-minutes-quota): Limit the usage of pipeline minutes for shared runners. **(STARTER ONLY)**
+- [Shared runners pipelines quota](../user/admin_area/settings/continuous_integration.md#shared-runners-pipeline-minutes-quota): Limit the usage of pipeline minutes for shared runners.
- [Enable/disable Auto DevOps](../topics/autodevops/index.md#enablingdisabling-auto-devops): Enable or disable Auto DevOps for your instance.
## Snippet settings
@@ -213,7 +210,7 @@ Learn how to install, configure, update, and maintain your GitLab instance.
## Analytics
-- [Pseudonymizer](pseudonymizer.md): Export data from a GitLab database to CSV files in a secure way. **(ULTIMATE)**
+- [Pseudonymizer](pseudonymizer.md): Export data from a GitLab database to CSV files in a secure way.
## Troubleshooting
diff --git a/doc/administration/integration/plantuml.md b/doc/administration/integration/plantuml.md
index a7458999aaa..a5997bee2db 100644
--- a/doc/administration/integration/plantuml.md
+++ b/doc/administration/integration/plantuml.md
@@ -37,7 +37,7 @@ A simple `docker-compose.yml` file would be:
version: "3"
services:
gitlab:
- image: 'gitlab/gitlab-ce:12.2.5-ce.0'
+ image: 'gitlab/gitlab-ee:12.2.5-ee.0'
environment:
GITLAB_OMNIBUS_CONFIG: |
nginx['custom_gitlab_server_config'] = "location /-/plantuml/ { \n proxy_cache off; \n proxy_pass http://plantuml:8080/; \n}\n"
diff --git a/doc/administration/monitoring/performance/index.md b/doc/administration/monitoring/performance/index.md
index 5b82696ae4b..072baa16e29 100644
--- a/doc/administration/monitoring/performance/index.md
+++ b/doc/administration/monitoring/performance/index.md
@@ -61,3 +61,14 @@ half above the interval. For example, for a user defined interval of 15 seconds
the actual interval can be anywhere between 7.5 and 22.5. The interval is
re-generated for every sampling run instead of being generated one time and reused
for the duration of the process' lifetime.
+
+User defined intervals can be specified by means of environment variables.
+The following environment variables are recognized:
+
+- `RUBY_SAMPLER_INTERVAL_SECONDS`
+- `DATABASE_SAMPLER_INTERVAL_SECONDS`
+- `ACTION_CABLE_SAMPLER_INTERVAL_SECONDS`
+- `PUMA_SAMPLER_INTERVAL_SECONDS`
+- `UNICORN_SAMPLER_INTERVAL_SECONDS`
+- `THREADS_SAMPLER_INTERVAL_SECONDS`
+- `GLOBAL_SEARCH_SAMPLER_INTERVAL_SECONDS`
diff --git a/doc/development/api_graphql_styleguide.md b/doc/development/api_graphql_styleguide.md
index 832a89ecac1..d73c3a8d6f6 100644
--- a/doc/development/api_graphql_styleguide.md
+++ b/doc/development/api_graphql_styleguide.md
@@ -760,7 +760,7 @@ To limit the amount of queries performed, we can use [BatchLoader](graphql_guide
### Writing resolvers
-Our code should aim to be thin declarative wrappers around finders and services. You can
+Our code should aim to be thin declarative wrappers around finders and [services](../development/reusing_abstractions.md#service-classes). You can
repeat lists of arguments, or extract them to concerns. Composition is preferred over
inheritance in most cases. Treat resolvers like controllers: resolvers should be a DSL
that compose other application abstractions.
@@ -1256,6 +1256,10 @@ single mutation when multiple are performed within a single request.
### The `resolve` method
+Similar to [writing resolvers](#writing-resolvers), the `resolve` method of a mutation
+should aim to be a thin declarative wrapper around a
+[service](../development/reusing_abstractions.md#service-classes).
+
The `resolve` method receives the mutation's arguments as keyword arguments.
From here, we can call the service that modifies the resource.
@@ -1352,6 +1356,7 @@ Key points:
- Errors may be reported to users either at `$root.errors` (top-level error) or at
`$root.data.mutationName.errors` (mutation errors). The location depends on what kind of error
this is, and what information it holds.
+- Mutation fields [must have `null: true`](https://graphql-ruby.org/mutations/mutation_errors#nullable-mutation-payload-fields)
Consider an example mutation `doTheThing` that returns a response with
two fields: `errors: [String]`, and `thing: ThingType`. The specific nature of
diff --git a/doc/development/documentation/feature_flags.md b/doc/development/documentation/feature_flags.md
index 59298c5345f..7547ec59fb2 100644
--- a/doc/development/documentation/feature_flags.md
+++ b/doc/development/documentation/feature_flags.md
@@ -37,12 +37,10 @@ therefore, it indicates that it cannot be done by regular users of GitLab.com.
### Features disabled by default
-For features disabled by default, if they cannot be used yet due to lack of
-completeness, or if they're still under internal evaluation (for example, for
-performance implications) do **not document them**: add (or merge) the docs
-only when the feature is safe and ready to use and test by end-users.
+For features disabled by default, add or improve the docs with every change in line with the
+[definition of done](../contributing/merge_request_workflow.md#definition-of-done).
-For feature flags disabled by default, if they can be used by end users:
+Include details of the feature flag in the documentation:
- Say that it's disabled by default.
- Say whether it's enabled on GitLab.com.
diff --git a/doc/install/installation.md b/doc/install/installation.md
index 49bce16e176..aa6e64f3710 100644
--- a/doc/install/installation.md
+++ b/doc/install/installation.md
@@ -1056,31 +1056,30 @@ sudo yum groupinstall 'Development Tools'
### Error compiling GitLab assets
-While compiling assets, you might get the following error:
+While compiling assets, you may receive the following error message:
```plaintext
Killed
error Command failed with exit code 137.
```
-This happens because when a container runs out of memory, YARN automatically kills it.
+This can occur when Yarn kills a container that runs out of memory. To fix this:
-To fix this, first make sure you increase your machine's memory (8GB of memory should be good),
-and then run the following commands:
+1. Increase your system's memory to at least 8 GB.
-1. Clean the assets:
+1. Run this command to clean the assets:
```shell
sudo -u git -H bundle exec rake gitlab:assets:clean RAILS_ENV=production NODE_ENV=production
```
-1. Run the `yarn` command again to ensure any conflicts are resolved:
+1. Run the `yarn` command again to resolve any conflicts:
```shell
sudo -u git -H yarn install --production --pure-lockfile
```
-1. Recompile assets:
+1. Recompile the assets:
```shell
sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production NODE_ENV=production
diff --git a/lib/gitlab/git/diff_collection.rb b/lib/gitlab/git/diff_collection.rb
index 8df4bc3de05..19462e6cb02 100644
--- a/lib/gitlab/git/diff_collection.rb
+++ b/lib/gitlab/git/diff_collection.rb
@@ -13,7 +13,7 @@ module Gitlab
def self.default_limits(project: nil)
if Feature.enabled?(:increased_diff_limits, project)
- { max_files: 200, max_lines: 7500 }
+ { max_files: 300, max_lines: 10000 }
else
{ max_files: 100, max_lines: 5000 }
end
diff --git a/lib/gitlab/metrics/samplers/action_cable_sampler.rb b/lib/gitlab/metrics/samplers/action_cable_sampler.rb
index 9f4979fa673..043d2ae84cc 100644
--- a/lib/gitlab/metrics/samplers/action_cable_sampler.rb
+++ b/lib/gitlab/metrics/samplers/action_cable_sampler.rb
@@ -4,9 +4,9 @@ module Gitlab
module Metrics
module Samplers
class ActionCableSampler < BaseSampler
- SAMPLING_INTERVAL_SECONDS = 5
+ DEFAULT_SAMPLING_INTERVAL_SECONDS = 5
- def initialize(interval = SAMPLING_INTERVAL_SECONDS, action_cable: ::ActionCable.server)
+ def initialize(interval = nil, action_cable: ::ActionCable.server)
super(interval)
@action_cable = action_cable
end
diff --git a/lib/gitlab/metrics/samplers/base_sampler.rb b/lib/gitlab/metrics/samplers/base_sampler.rb
index 39a49187e45..7f9055fed5d 100644
--- a/lib/gitlab/metrics/samplers/base_sampler.rb
+++ b/lib/gitlab/metrics/samplers/base_sampler.rb
@@ -9,7 +9,9 @@ module Gitlab
attr_reader :interval
# interval - The sampling interval in seconds.
- def initialize(interval = self.class::SAMPLING_INTERVAL_SECONDS)
+ def initialize(interval = nil)
+ interval ||= ENV[interval_env_key]&.to_i
+ interval ||= self.class::DEFAULT_SAMPLING_INTERVAL_SECONDS
interval_half = interval.to_f / 2
@interval = interval
@@ -50,6 +52,14 @@ module Gitlab
attr_reader :running
+ def sampler_class
+ self.class.name.demodulize
+ end
+
+ def interval_env_key
+ "#{sampler_class.underscore.upcase}_INTERVAL_SECONDS"
+ end
+
def start_working
@running = true
diff --git a/lib/gitlab/metrics/samplers/database_sampler.rb b/lib/gitlab/metrics/samplers/database_sampler.rb
index 9ee4b0960c5..60ae22df607 100644
--- a/lib/gitlab/metrics/samplers/database_sampler.rb
+++ b/lib/gitlab/metrics/samplers/database_sampler.rb
@@ -4,7 +4,7 @@ module Gitlab
module Metrics
module Samplers
class DatabaseSampler < BaseSampler
- SAMPLING_INTERVAL_SECONDS = 5
+ DEFAULT_SAMPLING_INTERVAL_SECONDS = 5
METRIC_PREFIX = 'gitlab_database_connection_pool_'
diff --git a/lib/gitlab/metrics/samplers/puma_sampler.rb b/lib/gitlab/metrics/samplers/puma_sampler.rb
index d295beb59f1..848a55e59ff 100644
--- a/lib/gitlab/metrics/samplers/puma_sampler.rb
+++ b/lib/gitlab/metrics/samplers/puma_sampler.rb
@@ -4,7 +4,7 @@ module Gitlab
module Metrics
module Samplers
class PumaSampler < BaseSampler
- SAMPLING_INTERVAL_SECONDS = 5
+ DEFAULT_SAMPLING_INTERVAL_SECONDS = 5
def metrics
@metrics ||= init_metrics
diff --git a/lib/gitlab/metrics/samplers/ruby_sampler.rb b/lib/gitlab/metrics/samplers/ruby_sampler.rb
index dac9fbd1247..76175b465e4 100644
--- a/lib/gitlab/metrics/samplers/ruby_sampler.rb
+++ b/lib/gitlab/metrics/samplers/ruby_sampler.rb
@@ -6,7 +6,7 @@ module Gitlab
module Metrics
module Samplers
class RubySampler < BaseSampler
- SAMPLING_INTERVAL_SECONDS = 60
+ DEFAULT_SAMPLING_INTERVAL_SECONDS = 60
GC_REPORT_BUCKETS = [0.005, 0.01, 0.02, 0.04, 0.07, 0.1, 0.5].freeze
def initialize(*)
diff --git a/lib/gitlab/metrics/samplers/threads_sampler.rb b/lib/gitlab/metrics/samplers/threads_sampler.rb
index 05acef7ce0c..a460594fb59 100644
--- a/lib/gitlab/metrics/samplers/threads_sampler.rb
+++ b/lib/gitlab/metrics/samplers/threads_sampler.rb
@@ -4,7 +4,7 @@ module Gitlab
module Metrics
module Samplers
class ThreadsSampler < BaseSampler
- SAMPLING_INTERVAL_SECONDS = 5
+ DEFAULT_SAMPLING_INTERVAL_SECONDS = 5
KNOWN_PUMA_THREAD_NAMES = ['puma worker check pipe', 'puma server',
'puma threadpool reaper', 'puma threadpool trimmer',
'puma worker check pipe', 'puma stat payload'].freeze
diff --git a/lib/gitlab/metrics/samplers/unicorn_sampler.rb b/lib/gitlab/metrics/samplers/unicorn_sampler.rb
index d7935d65e12..2fa324f3fea 100644
--- a/lib/gitlab/metrics/samplers/unicorn_sampler.rb
+++ b/lib/gitlab/metrics/samplers/unicorn_sampler.rb
@@ -4,6 +4,8 @@ module Gitlab
module Metrics
module Samplers
class UnicornSampler < BaseSampler
+ DEFAULT_SAMPLING_INTERVAL_SECONDS = 5
+
def metrics
@metrics ||= init_metrics
end
diff --git a/spec/lib/gitlab/metrics/samplers/action_cable_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/action_cable_sampler_spec.rb
index 7f05f35c941..f751416f4ec 100644
--- a/spec/lib/gitlab/metrics/samplers/action_cable_sampler_spec.rb
+++ b/spec/lib/gitlab/metrics/samplers/action_cable_sampler_spec.rb
@@ -7,15 +7,7 @@ RSpec.describe Gitlab::Metrics::Samplers::ActionCableSampler do
subject { described_class.new(action_cable: action_cable) }
- describe '#interval' do
- it 'samples every five seconds by default' do
- expect(subject.interval).to eq(5)
- end
-
- it 'samples at other intervals if requested' do
- expect(described_class.new(11).interval).to eq(11)
- end
- end
+ it_behaves_like 'metrics sampler', 'ACTION_CABLE_SAMPLER'
describe '#sample' do
let(:pool) { instance_double(Concurrent::ThreadPoolExecutor) }
diff --git a/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb
index b94d19ff227..9572e9f50be 100644
--- a/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb
+++ b/spec/lib/gitlab/metrics/samplers/database_sampler_spec.rb
@@ -5,15 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Metrics::Samplers::DatabaseSampler do
subject { described_class.new }
- describe '#interval' do
- it 'samples every five seconds by default' do
- expect(subject.interval).to eq(5)
- end
-
- it 'samples at other intervals if requested' do
- expect(described_class.new(11).interval).to eq(11)
- end
- end
+ it_behaves_like 'metrics sampler', 'DATABASE_SAMPLER'
describe '#sample' do
before do
diff --git a/spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb
index 214649d3e7e..2013435a074 100644
--- a/spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb
+++ b/spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb
@@ -11,15 +11,7 @@ RSpec.describe Gitlab::Metrics::Samplers::PumaSampler do
allow(Gitlab::Metrics::NullMetric).to receive(:instance).and_return(null_metric)
end
- describe '#interval' do
- it 'samples every five seconds by default' do
- expect(subject.interval).to eq(5)
- end
-
- it 'samples at other intervals if requested' do
- expect(described_class.new(11).interval).to eq(11)
- end
- end
+ it_behaves_like 'metrics sampler', 'PUMA_SAMPLER'
describe '#sample' do
before do
diff --git a/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb
index eb6c83096b9..6f1e0480197 100644
--- a/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb
+++ b/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb
@@ -10,6 +10,8 @@ RSpec.describe Gitlab::Metrics::Samplers::RubySampler do
allow(Gitlab::Metrics::NullMetric).to receive(:instance).and_return(null_metric)
end
+ it_behaves_like 'metrics sampler', 'RUBY_SAMPLER'
+
describe '#initialize' do
it 'sets process_start_time_seconds' do
freeze_time do
@@ -18,16 +20,6 @@ RSpec.describe Gitlab::Metrics::Samplers::RubySampler do
end
end
- describe '#interval' do
- it 'samples every sixty seconds by default' do
- expect(subject.interval).to eq(60)
- end
-
- it 'samples at other intervals if requested' do
- expect(described_class.new(11).interval).to eq(11)
- end
- end
-
describe '#sample' do
it 'adds a metric containing the process resident memory bytes' do
expect(Gitlab::Metrics::System).to receive(:memory_usage_rss).and_return(9000)
diff --git a/spec/lib/gitlab/metrics/samplers/threads_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/threads_sampler_spec.rb
index 19477589289..5dabafb7c0b 100644
--- a/spec/lib/gitlab/metrics/samplers/threads_sampler_spec.rb
+++ b/spec/lib/gitlab/metrics/samplers/threads_sampler_spec.rb
@@ -5,15 +5,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Metrics::Samplers::ThreadsSampler do
subject { described_class.new }
- describe '#interval' do
- it 'samples every five seconds by default' do
- expect(subject.interval).to eq(5)
- end
-
- it 'samples at other intervals if requested' do
- expect(described_class.new(11).interval).to eq(11)
- end
- end
+ it_behaves_like 'metrics sampler', 'THREADS_SAMPLER'
describe '#sample' do
before do
diff --git a/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb
index 9f2180c4170..7971a7cabd5 100644
--- a/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb
+++ b/spec/lib/gitlab/metrics/samplers/unicorn_sampler_spec.rb
@@ -5,6 +5,8 @@ require 'spec_helper'
RSpec.describe Gitlab::Metrics::Samplers::UnicornSampler do
subject { described_class.new(1.second) }
+ it_behaves_like 'metrics sampler', 'UNICORN_SAMPLER'
+
describe '#sample' do
let(:unicorn) { Module.new }
let(:raindrops) { double('raindrops') }
diff --git a/spec/support/shared_examples/metrics/sampler_shared_examples.rb b/spec/support/shared_examples/metrics/sampler_shared_examples.rb
new file mode 100644
index 00000000000..ebf199c3a8d
--- /dev/null
+++ b/spec/support/shared_examples/metrics/sampler_shared_examples.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'metrics sampler' do |env_prefix|
+ context 'when sampling interval is passed explicitly' do
+ subject { described_class.new(42) }
+
+ specify { expect(subject.interval).to eq(42) }
+ end
+
+ context 'when sampling interval is passed through the environment' do
+ subject { described_class.new }
+
+ before do
+ stub_env("#{env_prefix}_INTERVAL_SECONDS", '42')
+ end
+
+ specify { expect(subject.interval).to eq(42) }
+ end
+
+ context 'when no sampling interval is passed anywhere' do
+ subject { described_class.new }
+
+ it 'uses the hardcoded default' do
+ expect(subject.interval).to eq(described_class::DEFAULT_SAMPLING_INTERVAL_SECONDS)
+ end
+ end
+end