debian-mirror-gitlab/doc/administration/troubleshooting/gitlab_rails_cheat_sheet.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

661 lines
19 KiB
Markdown
Raw Normal View History

2019-12-04 20:38:33 +05:30
---
2022-07-23 23:45:48 +05:30
stage: Systems
2021-02-22 17:27:13 +05:30
group: Distribution
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2019-12-04 20:38:33 +05:30
---
2021-03-11 19:13:27 +05:30
# GitLab Rails Console Cheat Sheet **(FREE SELF)**
2019-12-04 20:38:33 +05:30
2019-12-21 20:55:43 +05:30
This is the GitLab Support Team's collection of information regarding the GitLab Rails
2019-12-04 20:38:33 +05:30
console, for use while troubleshooting. It is listed here for transparency,
2022-08-13 15:12:31 +05:30
and for users with experience with these tools. If you are currently
2021-03-11 19:13:27 +05:30
having an issue with GitLab, it is highly recommended that you first check
2022-08-13 15:12:31 +05:30
our guide on [our Rails console](../operations/rails_console.md),
2021-03-11 19:13:27 +05:30
and your [support options](https://about.gitlab.com/support/), before attempting to use
2019-12-04 20:38:33 +05:30
this information.
2021-02-22 17:27:13 +05:30
WARNING:
2021-10-27 15:23:28 +05:30
Some of these scripts could be damaging if not run correctly,
2019-12-04 20:38:33 +05:30
or under the right conditions. We highly recommend running them under the
guidance of a Support Engineer, or running them in a test environment with a
backup of the instance ready to be restored, just in case.
2021-02-22 17:27:13 +05:30
WARNING:
2021-10-27 15:23:28 +05:30
As GitLab changes, changes to the code are inevitable,
2019-12-04 20:38:33 +05:30
and so some scripts may not work as they once used to. These are not kept
up-to-date as these scripts/commands were added as they were found/needed. As
mentioned above, we recommend running these scripts under the supervision of a
2021-11-18 22:05:49 +05:30
Support Engineer, who can also verify that they continue to work as they
2019-12-04 20:38:33 +05:30
should and, if needed, update the script for the latest version of GitLab.
2021-01-29 00:20:46 +05:30
## Attributes
View available attributes, formatted using pretty print (`pp`).
For example, determine what attributes contain users' names and email addresses:
```ruby
u = User.find_by_username('someuser')
pp u.attributes
```
Partial output:
```plaintext
{"id"=>1234,
"email"=>"someuser@example.com",
"sign_in_count"=>99,
"name"=>"S User",
"username"=>"someuser",
"first_name"=>nil,
"last_name"=>nil,
"bot_type"=>nil}
```
Then make use of the attributes, [testing SMTP, for example](https://docs.gitlab.com/omnibus/settings/smtp.html#testing-the-smtp-configuration):
```ruby
e = u.email
n = u.name
Notify.test_email(e, "Test email for #{n}", 'Test email').deliver_now
#
Notify.test_email(u.email, "Test email for #{u.name}", 'Test email').deliver_now
```
2022-01-26 12:08:38 +05:30
## Imports and exports
### Import a project
2019-12-04 20:38:33 +05:30
```ruby
# Find the project and get the error
p = Project.find_by_full_path('<username-or-group>/<project-name>')
p.import_error
# To finish the import on GitLab running version before 11.6
p.import_finish
# To finish the import on GitLab running version 11.6 or after
p.import_state.mark_as_failed("Failed manually through console.")
```
### Rename imported repository
In a specific situation, an imported repository needed to be renamed. The Support
Team was informed of a backup restore that failed on a single repository, which created
2020-06-23 00:09:42 +05:30
the project with an empty repository. The project was successfully restored to a development
2019-12-04 20:38:33 +05:30
instance, then exported, and imported into a new project under a different name.
The Support Team was able to transfer the incorrectly named imported project into the
correctly named empty project using the steps below.
Move the new repository to the empty repository:
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
mv /var/opt/gitlab/git-data/repositories/<group>/<new-project> /var/opt/gitlab/git-data/repositories/<group>/<empty-project>
```
Make sure the permissions are correct:
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
chown -R git:git <path-to-directory>.git
```
Clear the cache:
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
sudo gitlab-rake cache:clear
```
2022-01-26 12:08:38 +05:30
### Export a project
2021-02-22 17:27:13 +05:30
2021-10-27 15:23:28 +05:30
It's typically recommended to export a project through [the web interface](../../user/project/settings/import_export.md#export-a-project-and-its-data) or through [the API](../../api/project_import_export.md). In situations where this is not working as expected, it may be preferable to export a project directly via the Rails console:
2021-02-22 17:27:13 +05:30
```ruby
2022-01-26 12:08:38 +05:30
user = User.find_by_username('<username>')
# Sufficient permissions needed
# Read https://docs.gitlab.com/ee/user/permissions.html#project-members-permissions
project = Project.find_by_full_path('<username-or-group>/<project-name')
2021-02-22 17:27:13 +05:30
Projects::ImportExport::ExportService.new(project, user).execute
```
2021-11-18 22:05:49 +05:30
If this all runs successfully, you see an output like the following before being returned to the Rails console prompt:
2021-02-22 17:27:13 +05:30
```ruby
=> nil
```
2022-08-13 15:12:31 +05:30
The exported project is located in a `.tar.gz` file in `/var/opt/gitlab/gitlab-rails/uploads/-/system/import_export_upload/export_file/`.
2021-02-22 17:27:13 +05:30
2022-08-13 15:12:31 +05:30
If this fails, [enable verbose logging](../operations/rails_console.md#looking-up-database-persisted-objects),
2022-01-26 12:08:38 +05:30
repeat the above procedure after,
and report the output to
[GitLab Support](https://about.gitlab.com/support/).
2019-12-04 20:38:33 +05:30
## Mirrors
### Find mirrors with "bad decrypt" errors
2022-03-02 08:16:31 +05:30
This content has been converted to a Rake task, see [verify database values can be decrypted using the current secrets](../raketasks/check.md#verify-database-values-can-be-decrypted-using-the-current-secrets).
2019-12-04 20:38:33 +05:30
### Transfer mirror users and tokens to a single service account
2022-11-25 23:54:43 +05:30
This content has been moved to [Troubleshooting Repository mirroring](../../user/project/repository/mirror/index.md#transfer-mirror-users-and-tokens-to-a-single-service-account-in-rails-console).
2019-12-04 20:38:33 +05:30
## Users
2021-10-27 15:23:28 +05:30
### Create new user
```ruby
u = User.new(username: 'test_user', email: 'test@example.com', name: 'Test User', password: 'password', password_confirmation: 'password')
2021-11-18 22:05:49 +05:30
u.skip_confirmation! # Use it only if you wish user to be automatically confirmed. If skipped, user receives confirmation e-mail
2021-10-27 15:23:28 +05:30
u.save!
```
2019-12-04 20:38:33 +05:30
### Skip reconfirmation
```ruby
2021-10-27 15:23:28 +05:30
user = User.find_by_username('<username>')
2019-12-04 20:38:33 +05:30
user.skip_reconfirmation!
```
2021-10-27 15:23:28 +05:30
### Disable 2fa for single user
2022-08-13 15:12:31 +05:30
**In GitLab 13.5 and later:**
Use the code under [Disable 2FA | For a single user](../../security/two_factor_authentication.md#for-a-single-user) so that the target user
is notified that 2FA has been disabled.
**In GitLab 13.4 and earlier:**
2021-10-27 15:23:28 +05:30
```ruby
user = User.find_by_username('<username>')
user.disable_two_factor!
```
2019-12-04 20:38:33 +05:30
### Active users & Historical users
```ruby
# Active users on the instance, now
User.active.count
2021-01-03 14:25:43 +05:30
# Users taking a seat on the instance
2021-01-29 00:20:46 +05:30
User.billable.count
2021-01-03 14:25:43 +05:30
2019-12-04 20:38:33 +05:30
# The historical max on the instance as of the past year
2022-01-26 12:08:38 +05:30
::HistoricalData.max_historical_user_count(from: 1.year.ago.beginning_of_day, to: Time.current.end_of_day)
2019-12-04 20:38:33 +05:30
```
2022-08-13 15:12:31 +05:30
Using cURL and jq (up to a max 100, see [Pagination](../../api/index.md#pagination)):
2021-02-22 17:27:13 +05:30
2020-03-13 15:44:24 +05:30
```shell
2021-09-04 01:27:46 +05:30
curl --silent --header "Private-Token: ********************" \
"https://gitlab.example.com/api/v4/users?per_page=100&active" | jq --compact-output '.[] | [.id,.name,.username]'
2019-12-04 20:38:33 +05:30
```
2021-11-11 11:23:49 +05:30
### Update Daily Billable & Historical users
```ruby
# Forces recount of historical (max) users
::HistoricalDataWorker.new.perform
# Forces recount of daily billable users
identifier = Analytics::UsageTrends::Measurement.identifiers[:billable_users]
::Analytics::UsageTrends::CounterJobWorker.new.perform(identifier, User.minimum(:id), User.maximum(:id), Time.zone.now)
```
2019-12-04 20:38:33 +05:30
### Block or Delete Users that have no projects or groups
```ruby
users = User.where('id NOT IN (select distinct(user_id) from project_authorizations)')
2021-11-18 22:05:49 +05:30
# How many users are removed?
2019-12-04 20:38:33 +05:30
users.count
# If that count looks sane:
# You can either block the users:
2022-01-26 12:08:38 +05:30
users.each { |user| user.blocked? ? nil : user.block! }
2019-12-04 20:38:33 +05:30
# Or you can delete them:
# need 'current user' (your user) for auditing purposes
current_user = User.find_by(username: '<your username>')
users.each do |user|
DeleteUserWorker.perform_async(current_user.id, user.id)
end
```
2021-02-22 17:27:13 +05:30
### Deactivate Users that have no recent activity
```ruby
days_inactive = 90
inactive_users = User.active.where("last_activity_on <= ?", days_inactive.days.ago)
inactive_users.each do |user|
puts "user '#{user.username}': #{user.last_activity_on}"
user.deactivate!
end
```
2019-12-04 20:38:33 +05:30
### Block Users that have no recent activity
```ruby
2021-02-22 17:27:13 +05:30
days_inactive = 90
2019-12-04 20:38:33 +05:30
inactive_users = User.active.where("last_activity_on <= ?", days_inactive.days.ago)
inactive_users.each do |user|
puts "user '#{user.username}': #{user.last_activity_on}"
user.block!
end
```
2021-06-08 01:23:25 +05:30
### Find a user's max permissions for project/group
2019-12-04 20:38:33 +05:30
```ruby
user = User.find_by_username 'username'
project = Project.find_by_full_path 'group/project'
user.max_member_access_for_project project.id
```
```ruby
user = User.find_by_username 'username'
group = Group.find_by_full_path 'group'
user.max_member_access_for_group group.id
```
2022-04-04 11:22:00 +05:30
## Merge requests
2019-12-04 20:38:33 +05:30
2022-08-27 11:52:29 +05:30
### Close a merge request
2019-12-04 20:38:33 +05:30
```ruby
2021-04-29 21:17:54 +05:30
u = User.find_by_username('<username>')
2022-01-26 12:08:38 +05:30
p = Project.find_by_full_path('<namespace/project>')
m = p.merge_requests.find_by(iid: <iid>)
2022-08-27 11:52:29 +05:30
MergeRequests::CloseService.new(project: p, current_user: u).execute(m)
2019-12-04 20:38:33 +05:30
```
2019-12-21 20:55:43 +05:30
### Delete a merge request
```ruby
u = User.find_by_username('<username>')
2022-01-26 12:08:38 +05:30
p = Project.find_by_full_path('<namespace/project>')
m = p.merge_requests.find_by(iid: <iid>)
Issuable::DestroyService.new(project: m.project, current_user: u).execute(m)
2019-12-21 20:55:43 +05:30
```
2019-12-04 20:38:33 +05:30
### Rebase manually
```ruby
2021-04-29 21:17:54 +05:30
u = User.find_by_username('<username>')
2022-01-26 12:08:38 +05:30
p = Project.find_by_full_path('<namespace/project>')
m = p.merge_requests.find_by(iid: <iid>)
MergeRequests::RebaseService.new(project: m.target_project, current_user: u).execute(m)
2019-12-04 20:38:33 +05:30
```
2022-08-27 11:52:29 +05:30
### Set a merge request as merged
Use when a merge request was accepted and the changes merged into the Git repository,
but the merge request still shows as open.
If the changes are not merged yet, this action causes the merge request to
incorrectly show `merged into <branch-name>`.
```ruby
u = User.find_by_username('<username>')
p = Project.find_by_full_path('<namespace/project>')
m = p.merge_requests.find_by(iid: <iid>)
MergeRequests::PostMergeService.new(project: p, current_user: u).execute(m)
```
2019-12-04 20:38:33 +05:30
## CI
### Cancel stuck pending pipelines
2019-12-21 20:55:43 +05:30
For more information, see the [confidential issue](../../user/project/issues/confidential_issues.md)
`https://gitlab.com/gitlab-com/support-forum/issues/2449#note_41929707`.
2019-12-04 20:38:33 +05:30
```ruby
Ci::Pipeline.where(project_id: p.id).where(status: 'pending').count
2019-12-26 22:10:19 +05:30
Ci::Pipeline.where(project_id: p.id).where(status: 'pending').each {|p| p.cancel if p.stuck?}
2019-12-04 20:38:33 +05:30
Ci::Pipeline.where(project_id: p.id).where(status: 'pending').count
```
### Remove artifacts more than a week old
2020-05-24 23:13:21 +05:30
This section has been moved to the [job artifacts troubleshooting documentation](../job_artifacts.md#delete-job-artifacts-from-jobs-completed-before-a-specific-date).
2019-12-04 20:38:33 +05:30
### Find reason failure (for when build trace is empty) (Introduced in 10.3.0)
2020-06-23 00:09:42 +05:30
See <https://gitlab.com/gitlab-org/gitlab-foss/-/issues/41111>.
2019-12-04 20:38:33 +05:30
```ruby
build = Ci::Build.find(78420)
build.failure_reason
build.dependencies.each do |d| { puts "status: #{d.status}, finished at: #{d.finished_at},
completed: #{d.complete?}, artifacts_expired: #{d.artifacts_expired?}, erased: #{d.erased?}" }
```
2021-09-30 23:02:18 +05:30
### Try CI integration
2019-12-04 20:38:33 +05:30
```ruby
2021-04-29 21:17:54 +05:30
p = Project.find_by_full_path('<project_path>')
2019-12-04 20:38:33 +05:30
m = project.merge_requests.find_by(iid: )
2021-09-30 23:02:18 +05:30
m.project.try(:ci_integration)
2019-12-04 20:38:33 +05:30
```
2020-05-24 23:13:21 +05:30
### Validate the `.gitlab-ci.yml`
```ruby
project = Project.find_by_full_path 'group/project'
content = project.repository.gitlab_ci_yml_for(project.repository.root_ref_sha)
2021-03-08 18:12:59 +05:30
Gitlab::Ci::Lint.new(project: project, current_user: User.first).validate(content)
2020-05-24 23:13:21 +05:30
```
2019-12-04 20:38:33 +05:30
### Disable AutoDevOps on Existing Projects
```ruby
Project.all.each do |p|
p.auto_devops_attributes={"enabled"=>"0"}
p.save
end
```
2020-04-08 14:13:33 +05:30
### Obtain runners registration token
```ruby
Gitlab::CurrentSettings.current_application_settings.runners_registration_token
```
2022-03-02 08:16:31 +05:30
### Seed runners registration token
```ruby
appSetting = Gitlab::CurrentSettings.current_application_settings
appSetting.set_runners_registration_token('<new-runners-registration-token>')
appSetting.save!
```
2021-04-29 21:17:54 +05:30
### Run pipeline schedules manually
You can run pipeline schedules manually through the Rails console to reveal any errors that are usually not visible.
```ruby
# schedule_id can be obtained from Edit Pipeline Schedule page
schedule = Ci::PipelineSchedule.find_by(id: <schedule_id>)
# Select the user that you want to run the schedule for
user = User.find_by_username('<username>')
# Run the schedule
ps = Ci::CreatePipelineService.new(schedule.project, user, ref: schedule.ref).execute!(:schedule, ignore_skip_ci: true, save_on_errors: false, schedule: schedule)
```
2019-12-04 20:38:33 +05:30
## License
2020-06-23 00:09:42 +05:30
### See current license information
2019-12-04 20:38:33 +05:30
```ruby
2020-06-23 00:09:42 +05:30
# License information (name, company, email address)
License.current.licensee
# Plan:
2019-12-04 20:38:33 +05:30
License.current.plan
2020-06-23 00:09:42 +05:30
# Uploaded:
License.current.created_at
# Started:
License.current.starts_at
# Expires at:
License.current.expires_at
# Is this a trial license?
License.current.trial?
2022-08-13 15:12:31 +05:30
# License ID for lookup on CustomersDot
License.current.license_id
2022-08-27 11:52:29 +05:30
# License data in Base64-encoded ASCII format
License.current.data
2019-12-04 20:38:33 +05:30
```
### Check if a project feature is available on the instance
2021-09-04 01:27:46 +05:30
Features listed in <https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/models/license.rb>.
2019-12-04 20:38:33 +05:30
```ruby
License.current.feature_available?(:jira_dev_panel_integration)
```
### Check if a project feature is available in a project
2021-09-04 01:27:46 +05:30
Features listed in [`license.rb`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/models/license.rb).
2019-12-04 20:38:33 +05:30
```ruby
p = Project.find_by_full_path('<group>/<project>')
p.feature_available?(:jira_dev_panel_integration)
```
### Add a license through the console
```ruby
key = "<key>"
license = License.new(data: key)
license.save
License.current # check to make sure it applied
```
2021-12-11 22:18:48 +05:30
This is needed for example in a known edge-case with
[expired license and multiple LDAP servers](../auth/ldap/ldap-troubleshooting.md#expired-license-causes-errors-with-multiple-ldap-servers).
### Remove licenses
2022-05-07 20:08:51 +05:30
To clean up the [License History table](../../user/admin_area/license_file.md#view-license-details-and-history):
2021-12-11 22:18:48 +05:30
```ruby
TYPE = :trial?
# or :expired?
License.select(&TYPE).each(&:destroy!)
# or even License.all.each(&:destroy!)
```
2020-03-13 15:44:24 +05:30
## Registry
### Registry Disk Space Usage by Project
2022-11-25 23:54:43 +05:30
Find this content in the [Container Registry troubleshooting documentation](../packages/container_registry.md#registry-disk-space-usage-by-project).
2020-03-13 15:44:24 +05:30
2020-10-24 23:57:45 +05:30
### Run the Cleanup policy now
2022-08-13 15:12:31 +05:30
Find this content in the [Container Registry troubleshooting documentation](../packages/container_registry.md#run-the-cleanup-policy-now).
2020-10-24 23:57:45 +05:30
2019-12-04 20:38:33 +05:30
## Sidekiq
2022-08-13 15:12:31 +05:30
This content has been moved to [Troubleshooting Sidekiq](sidekiq.md).
2019-12-04 20:38:33 +05:30
## LFS
2020-04-22 19:07:51 +05:30
### Get information about LFS objects and associated project
2019-12-04 20:38:33 +05:30
```ruby
2021-11-11 11:23:49 +05:30
o = LfsObject.find_by(oid: "<oid>")
p = Project.find(LfsObjectsProject.find_by_lfs_object_id(o.id).project_id)
2019-12-04 20:38:33 +05:30
```
You can then delete these records from the database with:
```ruby
LfsObjectsProject.find_by_lfs_object_id(o.id).destroy
o.destroy
```
You would also want to combine this with deleting the LFS file in the LFS storage
area on disk. It remains to be seen exactly how or whether the deletion is useful, however.
## Decryption Problems
### Bad Decrypt Script (for encrypted variables)
2022-03-02 08:16:31 +05:30
This content has been converted to a Rake task, see [verify database values can be decrypted using the current secrets](../raketasks/check.md#verify-database-values-can-be-decrypted-using-the-current-secrets).
2019-12-04 20:38:33 +05:30
2020-07-10 23:44:40 +05:30
As an example of repairing, if `ProjectImportData Bad count:` is detected and the decision is made to delete the
2019-12-04 20:38:33 +05:30
encrypted credentials to allow manual reentry:
```ruby
# Find the ids of the corrupt ProjectImportData objects
total = 0
bad = []
ProjectImportData.find_each do |data|
begin
total += 1
data.credentials
rescue => e
bad << data.id
end
end
puts "Bad count: #{bad.count} / #{total}"
# See the bad ProjectImportData ids
bad
# Remove the corrupted credentials
import_data = ProjectImportData.where(id: bad)
import_data.each do |data|
data.update_columns({ encrypted_credentials: nil, encrypted_credentials_iv: nil, encrypted_credentials_salt: nil})
end
```
If `User OTP Secret Bad count:` is detected. For each user listed disable/enable
two-factor authentication.
2021-11-18 22:05:49 +05:30
The following script searches in some of the tables for encrypted tokens that are
2020-07-10 23:44:40 +05:30
causing decryption errors, and update or reset as needed:
2019-12-04 20:38:33 +05:30
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
wget -O /tmp/encrypted-tokens.rb https://gitlab.com/snippets/1876342/raw
gitlab-rails runner /tmp/encrypted-tokens.rb
```
2020-07-10 23:44:40 +05:30
### Decrypt Script for encrypted tokens
2022-03-02 08:16:31 +05:30
This content has been converted to a Rake task, see [verify database values can be decrypted using the current secrets](../raketasks/check.md#verify-database-values-can-be-decrypted-using-the-current-secrets).
2020-07-10 23:44:40 +05:30
2019-12-04 20:38:33 +05:30
## Geo
2022-10-11 01:57:18 +05:30
### Reverify all uploads (or any SSF data type which is verified)
1. SSH into a GitLab Rails node in the primary Geo site.
1. Open [Rails console](../operations/rails_console.md).
1. Mark all uploads as "pending verification":
```ruby
Upload.verification_state_table_class.each_batch do |relation|
relation.update_all(verification_state: 0)
end
```
1. This will cause the primary to start checksumming all Uploads.
1. When a primary successfully checksums a record, then all secondaries rechecksum as well, and they compare the values.
A similar thing can be done for all Models handled by the [Geo Self-Service Framework](../../development/geo/framework.md) which have implemented verification:
- `LfsObject`
- `MergeRequestDiff`
- `Packages::PackageFile`
- `Terraform::StateVersion`
- `SnippetRepository`
- `Ci::PipelineArtifact`
- `PagesDeployment`
- `Upload`
- `Ci::JobArtifact`
- `Ci::SecureFile`
NOTE:
`GroupWikiRepository` is not in the previous list since verification is not implemented.
There is an [issue to implement this functionality in the Admin UI](https://gitlab.com/gitlab-org/gitlab/-/issues/364729).
2019-12-04 20:38:33 +05:30
### Artifacts
2022-11-25 23:54:43 +05:30
Moved to [Geo replication troubleshooting](../geo/replication/troubleshooting.md#find-failed-artifacts).
2019-12-04 20:38:33 +05:30
### Repository verification failures
2022-11-25 23:54:43 +05:30
Moved to [Geo replication troubleshooting](../geo/replication/troubleshooting.md#repository-verification-failures).
2019-12-04 20:38:33 +05:30
### Resync repositories
2022-11-25 23:54:43 +05:30
Moved to [Geo replication troubleshooting](../geo/replication/troubleshooting.md#resync-repositories).
2021-01-29 00:20:46 +05:30
2022-08-13 15:12:31 +05:30
### Blob types
2021-04-17 20:07:23 +05:30
2022-11-25 23:54:43 +05:30
Moved to [Geo replication troubleshooting](../geo/replication/troubleshooting.md#blob-types).
2021-04-17 20:07:23 +05:30
2021-09-30 23:02:18 +05:30
## Generate Service Ping
2021-01-29 00:20:46 +05:30
2022-03-02 08:16:31 +05:30
The [Service Ping Guide](../../development/service_ping/index.md) in our developer documentation
has more information about Service Ping.
2022-01-26 12:08:38 +05:30
2021-09-30 23:02:18 +05:30
### Generate or get the cached Service Ping
2021-01-29 00:20:46 +05:30
```ruby
2022-04-04 11:22:00 +05:30
Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values, cached: true)
2021-01-29 00:20:46 +05:30
```
2021-09-30 23:02:18 +05:30
### Generate a fresh new Service Ping
2021-01-29 00:20:46 +05:30
2021-11-18 22:05:49 +05:30
This also refreshes the cached Service Ping displayed in the Admin Area
2021-01-29 00:20:46 +05:30
```ruby
2022-04-04 11:22:00 +05:30
Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values)
2021-01-29 00:20:46 +05:30
```
2021-02-22 17:27:13 +05:30
2021-09-30 23:02:18 +05:30
### Generate and print
2021-02-22 17:27:13 +05:30
2021-09-30 23:02:18 +05:30
Generates Service Ping data in JSON format.
2021-02-22 17:27:13 +05:30
```shell
rake gitlab:usage_data:generate
```
2022-01-26 12:08:38 +05:30
Generates Service Ping data in YAML format:
2022-03-02 08:16:31 +05:30
```shell
2022-01-26 12:08:38 +05:30
rake gitlab:usage_data:dump_sql_in_yaml
```
2021-09-30 23:02:18 +05:30
### Generate and send Service Ping
2021-02-22 17:27:13 +05:30
Prints the metrics saved in `conversational_development_index_metrics`.
```shell
rake gitlab:usage_data:generate_and_send
```
2022-11-25 23:54:43 +05:30
## GraphQL
Call a [GraphQL](../../api/graphql/getting_started.md) endpoint through the Rails console:
```ruby
query = <<~EOQ
query securityGetProjects($search: String!) {
projects(search: $search) {
nodes {
path
}
}
}
EOQ
variables = { "search": "gitlab" }
result = GitlabSchema.execute(query, variables: variables, context: { current_user: current_user })
result.to_h
```