debian-mirror-gitlab/doc/administration/job_logs.md

281 lines
9.9 KiB
Markdown
Raw Normal View History

2020-06-23 00:09:42 +05:30
---
stage: Verify
group: Runner
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
2020-06-23 00:09:42 +05:30
type: reference
---
2021-06-08 01:23:25 +05:30
# Job logs **(FREE SELF)**
2019-12-21 20:55:43 +05:30
2020-11-24 15:15:51 +05:30
Job logs are sent by a runner while it's processing a job. You can see
2021-09-04 01:27:46 +05:30
logs in job pages, pipelines, email notifications, and so on.
2019-12-21 20:55:43 +05:30
## Data flow
In general, there are two states for job logs: `log` and `archived log`.
In the following table you can see the phases a log goes through:
| Phase | State | Condition | Data flow | Stored path |
| -------------- | ------------ | ----------------------- | -----------------------------------------| ----------- |
2020-11-24 15:15:51 +05:30
| 1: patching | log | When a job is running | Runner => Puma => file storage | `#{ROOT_PATH}/gitlab-ci/builds/#{YYYY_mm}/#{project_id}/#{job_id}.log` |
2021-09-04 01:27:46 +05:30
| 2: archiving | archived log | After a job is finished | Sidekiq moves log to artifacts folder | `#{ROOT_PATH}/gitlab-rails/shared/artifacts/#{disk_hash}/#{YYYY_mm_dd}/#{job_id}/#{job_artifact_id}/job.log` |
| 3: uploading | archived log | After a log is archived | Sidekiq moves archived log to [object storage](#uploading-logs-to-object-storage) (if configured) | `#{bucket_name}/#{disk_hash}/#{YYYY_mm_dd}/#{job_id}/#{job_artifact_id}/job.log` |
2019-12-21 20:55:43 +05:30
2023-03-17 16:20:25 +05:30
The `ROOT_PATH` varies per environment:
- For the Linux package it's `/var/opt/gitlab`.
- For self-compiled installations it's `/home/git/gitlab`.
2019-12-21 20:55:43 +05:30
## Changing the job logs local location
2023-03-17 16:20:25 +05:30
NOTE:
For Docker installations, you can change the path where your data is mounted.
For the Helm chart, use object storage.
2019-12-21 20:55:43 +05:30
2023-03-17 16:20:25 +05:30
To change the location where the job logs are stored:
2019-12-21 20:55:43 +05:30
2023-03-17 16:20:25 +05:30
::Tabs
2019-12-21 20:55:43 +05:30
2023-03-17 16:20:25 +05:30
:::TabTitle Linux package (Omnibus)
2019-12-21 20:55:43 +05:30
2023-03-17 16:20:25 +05:30
1. Optional. If you have existing job logs, pause continuous integration data
processing by temporarily stopping Sidekiq:
2019-12-21 20:55:43 +05:30
2023-03-17 16:20:25 +05:30
```shell
sudo gitlab-ctl stop sidekiq
```
2021-01-29 00:20:46 +05:30
2023-03-17 16:20:25 +05:30
1. Set the new storage location in `/etc/gitlab/gitlab.rb`:
2021-01-29 00:20:46 +05:30
```ruby
2023-03-17 16:20:25 +05:30
gitlab_ci['builds_directory'] = '/mnt/gitlab-ci/builds'
2021-01-29 00:20:46 +05:30
```
2023-03-17 16:20:25 +05:30
1. Save the file and reconfigure GitLab:
2021-01-29 00:20:46 +05:30
2023-03-17 16:20:25 +05:30
```shell
sudo gitlab-ctl reconfigure
2021-01-29 00:20:46 +05:30
```
1. Use `rsync` to move job logs from the current location to the new location:
```shell
2023-03-17 16:20:25 +05:30
sudo rsync -avzh --remove-source-files --ignore-existing --progress /var/opt/gitlab/gitlab-ci/builds/ /mnt/gitlab-ci/builds/
2021-01-29 00:20:46 +05:30
```
Use `--ignore-existing` so you don't override new job logs with older versions of the same log.
2023-03-17 16:20:25 +05:30
1. If you opted to pause the continuous integration data processing, you can
start Sidekiq again:
```shell
sudo gitlab-ctl start sidekiq
```
2021-01-29 00:20:46 +05:30
1. Remove the old job logs storage location:
```shell
2023-03-17 16:20:25 +05:30
sudo rm -rf /var/opt/gitlab/gitlab-ci/builds
2021-01-29 00:20:46 +05:30
```
2023-03-17 16:20:25 +05:30
:::TabTitle Self-compiled (source)
1. Optional. If you have existing job logs, pause continuous integration data
processing by temporarily stopping Sidekiq:
```shell
# For systems running systemd
sudo systemctl stop gitlab-sidekiq
# For systems running SysV init
sudo service gitlab stop
```
2019-12-21 20:55:43 +05:30
2023-03-17 16:20:25 +05:30
1. Edit `/home/git/gitlab/config/gitlab.yml` to set the new storage location:
2019-12-21 20:55:43 +05:30
```yaml
2023-03-17 16:20:25 +05:30
production: &base
gitlab_ci:
builds_path: /mnt/gitlab-ci/builds
```
1. Save the file and restart GitLab:
```shell
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
```
1. Use `rsync` to move job logs from the current location to the new location:
```shell
sudo rsync -avzh --remove-source-files --ignore-existing --progress /home/git/gitlab/builds/ /mnt/gitlab-ci/builds/
```
Use `--ignore-existing` so you don't override new job logs with older versions of the same log.
1. If you opted to pause the continuous integration data processing, you can
start Sidekiq again:
```shell
# For systems running systemd
sudo systemctl start gitlab-sidekiq
# For systems running SysV init
sudo service gitlab start
```
1. Remove the old job logs storage location:
```shell
sudo rm -rf /home/git/gitlab/builds
2019-12-21 20:55:43 +05:30
```
2023-03-17 16:20:25 +05:30
::EndTabs
2019-12-21 20:55:43 +05:30
## Uploading logs to object storage
Archived logs are considered as [job artifacts](job_artifacts.md).
2023-03-17 16:20:25 +05:30
Therefore, when you [set up the object storage integration](job_artifacts.md#using-object-storage),
2019-12-21 20:55:43 +05:30
job logs are automatically migrated to it along with the other job artifacts.
2021-10-27 15:23:28 +05:30
See "Phase 3: uploading" in [Data flow](#data-flow) to learn about the process.
2019-12-21 20:55:43 +05:30
2021-01-03 14:25:43 +05:30
## Prevent local disk usage
If you want to avoid any local disk usage for job logs,
you can do so using one of the following options:
2021-09-30 23:02:18 +05:30
- Enable the [incremental logging](#incremental-logging-architecture) feature.
2021-01-03 14:25:43 +05:30
- Set the [job logs location](#changing-the-job-logs-local-location)
to an NFS drive.
2019-12-21 20:55:43 +05:30
## How to remove job logs
There isn't a way to automatically expire old job logs, but it's safe to remove
them if they're taking up too much space. If you remove the logs manually, the
2021-02-22 17:27:13 +05:30
job output in the UI is empty.
2019-12-21 20:55:43 +05:30
2023-03-17 16:20:25 +05:30
For example, to delete all job logs older than 60 days, run the following
command from a shell in your GitLab instance.
NOTE:
For the Helm chart, use the storage management tools provided with your object
storage.
2020-06-23 00:09:42 +05:30
2021-02-22 17:27:13 +05:30
WARNING:
2023-03-17 16:20:25 +05:30
The following command permanently deletes the log files and is irreversible.
::Tabs
:::TabTitle Linux package (Omnibus)
2020-06-23 00:09:42 +05:30
```shell
find /var/opt/gitlab/gitlab-rails/shared/artifacts -name "job.log" -mtime +60 -delete
```
2023-03-17 16:20:25 +05:30
:::TabTitle Docker
Assuming you mounted `/var/opt/gitlab` to `/srv/gitlab`:
```shell
find /srv/gitlab/gitlab-rails/shared/artifacts -name "job.log" -mtime +60 -delete
```
:::TabTitle Self-compiled (source)
```shell
find /home/git/gitlab/shared/artifacts -name "job.log" -mtime +60 -delete
```
::EndTabs
After the logs are deleted, you can find any broken file references by running
the Rake task that checks the
[integrity of the uploaded files](raketasks/check.md#uploaded-files-integrity).
For more information, see how to
[delete references to missing artifacts](raketasks/check.md#delete-references-to-missing-artifacts).
2021-09-04 01:27:46 +05:30
2021-06-08 01:23:25 +05:30
## Incremental logging architecture
2019-12-21 20:55:43 +05:30
2022-10-11 01:57:18 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/18169) in GitLab 10.8 [with a flag](feature_flags.md) named `ci_enable_live_trace`. Disabled by default.
> - [Enabled on GitLab.com](https://gitlab.com/gitlab-org/gitlab/-/issues/241471) in GitLab 13.6.
2021-06-08 01:23:25 +05:30
> - [Recommended for production use](https://gitlab.com/groups/gitlab-org/-/epics/4275) in GitLab 13.6.
> - [Recommended for production use with AWS S3](https://gitlab.com/gitlab-org/gitlab/-/issues/273498) in GitLab 13.7.
2021-11-11 11:23:49 +05:30
> - To use in GitLab self-managed instances, ask a GitLab administrator to [enable it](#enable-or-disable-incremental-logging).
2019-12-21 20:55:43 +05:30
2023-03-17 16:20:25 +05:30
By default, job logs are sent from the GitLab Runner in chunks and cached
temporarily on disk. After the job completes, a background job archives the job
log. The log is moved to the artifacts directory by default, or to object
storage if configured.
2021-06-08 01:23:25 +05:30
2023-03-17 16:20:25 +05:30
In a [scaled-out architecture](reference_architectures/index.md) with Rails and
Sidekiq running on more than one server, these two locations on the file system
have to be shared using NFS, which is not recommended. Instead:
2021-06-08 01:23:25 +05:30
2023-03-17 16:20:25 +05:30
1. Configure [object storage](job_artifacts.md#using-object-storage) for storing archived job logs.
2022-03-02 08:16:31 +05:30
1. [Enable the incremental logging feature](#enable-or-disable-incremental-logging), which uses Redis instead of disk space for temporary caching of job logs.
2021-06-08 01:23:25 +05:30
2023-03-17 16:20:25 +05:30
### Enable or disable incremental logging
Before you enable the feature flag:
- Review [the limitations of incremental logging](#limitations).
- [Enable object storage](job_artifacts.md#using-object-storage).
To enable incremental logging:
1. Open a [Rails console](operations/rails_console.md#starting-a-rails-console-session).
1. Enable the feature flag:
```ruby
Feature.enable(:ci_enable_live_trace)
```
Running jobs' logs continue to be written to disk, but new jobs use
incremental logging.
To disable incremental logging:
1. Open a [Rails console](operations/rails_console.md#starting-a-rails-console-session).
1. Disable the feature flag:
```ruby
Feature.disable(:ci_enable_live_trace)
```
Running jobs continue to use incremental logging, but new jobs write to the disk.
2021-06-08 01:23:25 +05:30
### Technical details
2019-12-21 20:55:43 +05:30
The data flow is the same as described in the [data flow section](#data-flow)
with one change: _the stored path of the first two phases is different_. This incremental
log architecture stores chunks of logs in Redis and a persistent store (object storage or database) instead of
2023-03-04 22:38:38 +05:30
file storage. Redis is used as first-class storage, and it stores up-to 128 KB
2021-01-29 00:20:46 +05:30
of data. After the full chunk is sent, it is flushed to a persistent store, either object storage (temporary directory) or database.
2021-02-22 17:27:13 +05:30
After a while, the data in Redis and a persistent store is archived to [object storage](#uploading-logs-to-object-storage).
2019-12-21 20:55:43 +05:30
2021-09-30 23:02:18 +05:30
The data are stored in the following Redis namespace: `Gitlab::Redis::TraceChunks`.
2019-12-21 20:55:43 +05:30
Here is the detailed data flow:
2020-11-24 15:15:51 +05:30
1. The runner picks a job from GitLab
1. The runner sends a piece of log to GitLab
2019-12-21 20:55:43 +05:30
1. GitLab appends the data to Redis
2023-03-04 22:38:38 +05:30
1. After the data in Redis reaches 128 KB, the data is flushed to a persistent store (object storage or the database).
2019-12-21 20:55:43 +05:30
1. The above steps are repeated until the job is finished.
2021-01-29 00:20:46 +05:30
1. After the job is finished, GitLab schedules a Sidekiq worker to archive the log.
2019-12-21 20:55:43 +05:30
1. The Sidekiq worker archives the log to object storage and cleans up the log
in Redis and a persistent store (object storage or the database).
2021-06-08 01:23:25 +05:30
### Limitations
2019-12-21 20:55:43 +05:30
2022-07-16 23:28:13 +05:30
- [Redis Cluster is not supported](https://gitlab.com/gitlab-org/gitlab/-/issues/224171).
2023-03-17 16:20:25 +05:30
- You must configure [object storage for CI/CD artifacts, logs, and builds](job_artifacts.md#using-object-storage)
2021-06-08 01:23:25 +05:30
before you enable the feature flag. After the flag is enabled, files cannot be written
to disk, and there is no protection against misconfiguration.
- There is [an epic tracking other potential limitations and improvements](https://gitlab.com/groups/gitlab-org/-/epics/3791).