Skip to content
ImagineWorld

Introducing the GitLab Architecture

node_idnode-book_mastering-gitlab-12_chapter-01-introducing-the-gitlab-architecture
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num1
chapter_titleIntroducing the GitLab Architecture
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 1 — Introducing the GitLab Architecture

Section titled “Chapter 1 — Introducing the GitLab Architecture”

This section will give you a solid understanding of GitLab deployment options and GitLab component architecture, leaving you able to install and configure GitLab on-premises and in the cloud.

Understanding the context of the GitLab project will help us to appreciate the choices that were made with regard to the design of the GitLab workflow. The GitLab project started out as a small, open source project, and has grown to be an organization of 400 people and thousands of volunteers. It is currently available in two versions, a free Community Edition (CE) and an Enterprise Edition (EE) with a proprietary license. There are several tiers of support for the enterprise version. Although it is proprietary licensed, the source code for that version is publicly available from GitLab.

To master GitLab, it is necessary to have a solid understanding of its individual components. In this chapter, we will look at the basic components of a GitLab installation, paying special attention to GitLab Continuous Integration (CI) and the accompanying runners. As the different components can be distributed across servers or even cloud providers, we will also provide an overview of those providers and how GitLab views them.

In this chapter, we will be covering the following topics:

  • The origins of GitLab
  • GitLab CE or EE
  • The core components of GitLab
  • GitLab CI
  • GitLab Runners
  • Cloud native

To follow along with the instructions in this chapter, please download the Git repository with examples, commands and instructions, available at GitHub: https://github.com/PacktPublishing/Mastering-GitLab-12/tree/master/Chapter01. Look in the Readme.md file for a general explanation of the content of the directory.

To run or install software used in this chapter you need one of the following platforms:

  • Debian 10 Linux codename ‘Buster’
  • CentOS 7.x or RHEL (Red Hat Enterprise Linux) 7.x
  • macOS Sierra or later

The story began in 2011, when Dimitri Zaporozhets, a web programmer from Ukraine, was faced with a common problem. He wanted to switch to Git for version management and GitHub to collaborate, but that was not allowed in his company. He needed a tool that did not hinder him in developing code and was easy to use. Like many developers, he had issues with the collaboration tool that he was obliged to use. To get around those issues, he created his side project in Ruby on Rails: GitLab. Together with his colleague, Valery Sizov, he developed this project alongside his regular work.

After this initiative, the project grew enormously:

DateFact
2011Sytze Sybrandij, the future CEO of GitLab, is impressed by the GitLab project and code, and offers Zaporozhets the opportunity to try to commercialize it via https://about.gitlab.com/.
2012GitLab was announced to a broader audience via Hacker News (https://news.ycombinator.com/item?id=4428278).
2013Dimitri Zaporozhets decides to work full-time on GitLab and joins the company.
2015GitLab becomes part of the Y Combinator class and received VC funding that year.
2018GitLab receives another 100millionofVCfundingandisvaluedat100 million of VC funding and is valued at 1 billion.
2019The GitLab company employs over 600 employees.

The initial idea of GitLab was to earn money from open source technology by offering support services. However, what happened was that companies started to bring in consultants only to upgrade GitLab, and then they would stop the service contract. It became clear that going for a 100% open source was not going to be competitive. Instead of this, therefore, they chose open core. Under open core, a company releases a core software system under an open source license. A different version of the software is sold under a commercial license and contains more features.

So, GitLab was split up into two editions: an open source version, and an enterprise version.

The core of the GitLab software is called the CE. It is distributed under the MIT license, which is a permissive free software license created at the Massachusetts Institute of Technology. You are allowed to modify the software and use it in your creations.

No feature that ever made it to CE will ever be removed, or moved to a closed source version. When GitLab EE was created in 2013, it was, at its core, GitLab CE, but it had additional enterprise features, such as Lightweight Directory Access Protocol (LDAP) groups. Those features are not open source, per se, but can be added to the core version if they are perceived by the company as a core feature. The idea was that companies should also contribute as much as possible to solving problems and creating new features.

In 2016, the GitLab EE product was divided into three tiers: Starter, Premium, and Ultimate. Each tier is about five times more expensive than the previous one and contains more features and support options, as mentioned in the following table:

VersionFeatures (short list)
StarterEverything on core GitLab CE: - CI/CD - Project Issue Board - Mattermost integrations - Time tracking - GitLab pages
PremiumMore enterprise features such as the following: - Maven and NPM repository functionality - Protected environments - Burndown charts - Multiple LDAP servers and Active Directory support
UltimateAll options, including the following: - All security scanning tools - Epics - Free guest users - Web terminal for the web IDE

GitLab has a lot of features, but let’s concentrate first on the basic building blocks.

GitLab is not a monolithic application. It tries to follow the Unix philosophy, which means that a software module should do only one particular thing, and do it well. The components that GitLab is made of are not as small and elegant as Unix’s awk and sed, but each component has a single purpose. You can find a high-level overview of these components in the following diagram:

Gitlab started as a pure Ruby on Rails application, but some components were later redesigned using Go. Ruby on Rails is a development framework built on top of the Ruby programming language. It implements a model-view-controller pattern and offers methods to connect to different databases (for example, ActiveRecord). It values convention over configuration and don’t-repeat-yourself (DRY) programming. It is very well suited to rapid development, and at the same time, it is highly performant and has many features.

Let’s dive a little deeper into those components in order to understand their roles.

The Unicorn web component cannot be used directly as it does not offer all the features for handling clients. The reverse proxy that is bundled by default is NGINX. It is also possible to use Apache as a frontend for GitLab, but it is preferable to use NGINX. There are many web servers available that could be installed in front of Unicorn, but in the end, there are basically two types, which are as follows:

  • Process-based (forking or threaded)
  • Asynchronous

NGINX and lighttpd are probably the two most-well known asynchronous servers. Apache is without a doubt the de facto standard process-based server. The biggest difference between the two types is how they handle scalability. For a process-based server, any new connections require a thread, while an event-driven, asynchronous server such as NGINX only needs a few threads (or, theoretically, only one). For lighter workloads, this does not matter much, but you will see a big difference when the number of connections grows, especially in terms of RAM. When serving tens of thousands of simultaneous connections, the amount of RAM used by NGINX would still hover around a couple of megabytes. Apache would either use hundreds, or it would not work at all. This is why NGINX is the better choice.

The first thing you will want to look at are the log files which by default are called error.log and access.log. In a GitLab environment installed from source these log files will typically reside in /var/log/nginx/ and in a GitLab omnibus install in /var/log/gitlab/nginx.

Following is an example of the error log:

# Optional: Set log level to only log entries with that severity or above

Section titled “# Optional: Set log level to only log entries with that severity or above”
2019/09/08 20:45:14 [crit] 2387#2387: *95 connect() to unix:/var/www/gitlab-app/tmp/sockets/unicorn.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /-/metrics HTTP/1.1", upstream: "http://unix:/var/www/gitlab-app/tmp/sockets/unicorn.sock:/-/metrics", host: "127.0.0.1:8080"

Unicorn is an HTTP server for applications that deal with well-performing clients on connections that show low latency and have enough bandwidth. It takes advantage of features that are present in the core of Linux-like systems. It is called a Rack HTTP server because it implements HTTP for Rack applications. Rack, in turn, is actually a Ruby implementation of a minimal interface to deal with web requests, which you can use in your code.

You can find the project at https://rack.github.io.

Unicorn runs as a daemon server in Unix and is programmed in Ruby and the C programming language. Using Ruby means that it can also run a Ruby on Rails application such as GitLab.

Maybe installing Unicorn produced errors, or you are experiencing bad performance that you suspect is caused by Unicorn not working properly.

There are several ways to find the cause. The log files can point you in the right direction.

The following output is what a Unicorn worker timeout looks like in unicorn_stderr.log. This is not necessarily bad; it just means that a new worker is spawned:

[2015-06-05T10:58:08.660325 #56227] ERROR -- : worker=10 PID:53009 timeout (61s > 60s), killing
[2015-06-05T10:58:08.699360 #56227] ERROR -- : reaped #<Process::Status: pid 53009 SIGKILL (signal 9)> worker=10
[2015-06-05T10:58:08.708141 #62538] INFO -- : worker=10 spawned pid=62538
[2015-06-05T10:58:08.708824 #62538] INFO -- : worker=10 ready

It could be that there are just not enough Unicorn workers available to respond to the requests at hand. NGINX buffers a lot of requests so we must check on the handover socket whether Unicorn can keep up. To do this,a little nifty script is available here: https://github.com/jahio/unicorn-status.

It can be called with the following command:

$ ruby unicorn_status.rb /var/opt/gitlab/gitlab-rails/sockets/gitlab.socket 10
Running infinite loop. Use CTRL+C to exit.
------------------------------------------
Active Requests Queued Requests
20 11

The first argument here is the unicorn_status.rb script, the second is the socket to connect to ../.socket, and the last argument is the poll interval (10).

On Linux, there is a mechanism called Out-of-Memory (OOM) Killer that will free up memory if the system is running low on memory, and you don’t have any swap memory left. It might kill Unicorn if it is using too much memory.

Use dmesg | egrep -i ‘killed process’ to search for OOM events:

[102335.3134488] Killed process 5567 (ruby) total-vm:13423004kB, anon-rss:554088kB

The ultimate way to debug Unicorn processes is to run strace on them:

  1. Run sudo gdb -p (PID) to attach to the Unicorn process.
  2. Run call (void) rb_backtrace() in the GDB console and find the generated Ruby backtrace in /var/log/gitlab/unicorn/unicorn_stderr.log:
from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:28:in \`run'
from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in \`kernel_load'
from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/bundler-1.16.2/lib/bundler/cli/exec.rb:74:in \`load'
from /opt/gitlab/embedded/bin/unicorn:23:in \`<top (required)>'<br/> from /opt/gitlab/embedded/bin/unicorn:23:in \`load
from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/unicorn-5.1.0/bin/unicorn:126:in \`<top (required)>'
from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:132:in \`start'
from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:508:in \`spawn_missing_workers'
from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:678:in \`worker_loop'
from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:678:in \`select'
  1. When you are done, leave GDB with detach and q.

Sidekiq is a framework for background job processing. It allows you to scale your application by performing work in the background. For more information on Sidekiq, consult the following website: https://github.com/mperham/sidekiq/wiki.

Each Sidekiq server process pulls jobs from the queue in Redis and processes them. Like your web processes, Sidekiq boots Rails so that your jobs and workers have the full Rails API available for use, including ActiveRecord. The server will instantiate the worker and call perform with the given arguments. Everything else is up to your code.

As with Unicorn, there are several ways to debug Sidekiq processing. The easiest way is to log in to GitLab as an administrator and view the logs from there, and especially view the queues and jobs on the Background Jobs page, as shown in the following screenshot:

Sometimes, you experience troubles and find situations on your Linux server.

As mentioned before, in the Unicorn section, the OOM Killer might kill Sidekiq if it is using too much memory.

Use dmesg | egrep -i ‘killed process’ to search for OOM events:

[102335.3134488] Killed process 8887 (ruby) total-vm:13523004kB, anon-rss:5540458kB

If Sidekiq isn’t doing any work and it seems stuck most of the time, this means that the program is waiting for something. A common wait situation is when you are doing remote network calls. If you think this could be the case, you could make Sidekiq processes dump a backtrace to the log by sending it a TTIN signal.

This is what a Sidekiq worker looks like in the log file in /var/log/gitlab/sidekiq/current:

{"severity":"INFO","time":"2019-06 23T19:00:14.493Z","class":"RemoteMirrorNotificationWorker","retry":3,"queue":"remote_mirror_notification","jid":"69eb806bfb66b82315bcb249","created_at":"2019-06-23T19:00:14.461Z","correlation_id":"toX0HnYW0s9","enqueued_at":"2019-06-23T19:00:14.461Z","pid":471,"message":"RemoteMirrorNotificationWorker JID-69eb806bfb66b82315bcb249: done: 0.03 sec","job_status":"done","duration":0.03,"completed_at":"2019-06-23T19:00:14.493Z"}

Since GitLab 12.0, the default output log format for Sidekiq is JSON, this makes it easier to read the log files into a tool like logstash because it is more structured.

The ultimate way to debug Sidekiq processes is to make it dump a backtrace via GDB:

  1. Run sudo gdb -p (PID) to attach to the Sidekiq worker process.
  2. Run call (void) rb_backtrace() in the GDB console and find the generated Ruby backtrace in /var/log/gitlab/sidekiq/current:
2018-09-21_19:55:03.48430 from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/redis-3.3.5/lib/redis/connection/ruby.rb:83:in \`_read_from_socket'
2018-09-21_19:55:03.48431 from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/redis-3.3.5/lib/redis/connection/ruby.rb:87:in \`rescue in _read_from_socket'
2018-09-21_19:55:03.48432 from /opt/gitlab/embedded/lib/ruby/gems/2.4.0/gems/redis-3.3.5/lib/redis/connection/ruby.rb:87:in \`select'
  1. It is very hard to read backtraces, but this process was doing network operations while being traced, we can see a (_read_from _socket). You can read the source code to check what it is doing (there are line numbers mentioned).
  2. When you are done, leave GDB with detach and quit.

You can also use other tracing tools to examine the behavior of the looping process. On Linux, for instance, strace -p <pid> allows you to view the system calls that are being made by the process.

This component is used to provide access to Git repositories through SSH. In fact, for pushes via the git-http protocol, it is also called instead of the Rails app. It’s essentially a small Ruby wrapper around the Git client. Git, through SSH, uses predefined commands that can be executed on the GitLab server. For authorization, it makes calls to the GitLab API. Before GitLab 5.0, this functionality was delivered by Gitolite and powered by the Perl programming language.

The source code of this project can be found here: https://gitlab.com/gitlab-org/gitlab-shell. You can see the following page:

You can install it locally, but it’s really only useful when deployed together with other GitLab components. When you have that installed (see Chapter 2, Installing GitLab, for instructions on how), the next section describes a way to debug when you have problems.

In an omnibus installation, the log file for GitLab Shell can be found in the following location:

/var/log/gitlab/gitlab-shell/gitlab-shell.log

Alternatively, it may be found in the following location, for installations from source:

/home/git/gitlab-shell/gitlab-shell.log

What you will generally find are log lines that concern the basic operations of GitLab Shell:

  • Git commands (such as git push and git pull).
  • Authorization calls to the GitLab Rails API to check whether you are allowed to connect
  • Execution of pre-receive hooks
  • Actions requested
  • Post-receive actions
  • Any custom post-receive actions

Here, we have listed some lines from the log file:

bash-4.1$ tail gitlab-shell.log
time="2018-09-26T08:59:53+02:00" level=info msg="executing git command" command="gitaly-upload-pack unix:/var/opt/gitlab/gitaly/gitaly.socket {\"repository\":{\"storage_name\":\"default\",\"relative_path\":\"xxx/xxx.git\",\"git_object_directory\":\"\",\"git_alternate_object_directories\":[],\"gl_repository\":\"xxx\"},\"gl_repository\":\"project-xx\",\"gl_id\":\"key-xx\",\"gl_username\":\"xxxxxx\"}" pid=18855 user="user with key key-xx"
time="2018-09-26T08:59:53+02:00" level=info msg="finished HTTP request" duration=0.228132057
method=POST pid=18890 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2018-09-26T08:59:54+02:00" level=info msg="finished HTTP request" duration=0.030036933 method=POST pid=18890 url="http://127.0.0.1:8080/api/v4/internal/pre_receive"
time="2018-09-26T08:59:54+02:00" level=info msg="finished HTTP request" duration=0.094035804 method=POST pid=18979 url="http://127.0.0.1:8080/api/v4/internal/post_receive"

One way to find errors is to look for certain patterns, such as failed, as follows. This particular error points to a 500 error from Unicorn while checking whether a user has the right authorization to make a call to the GitLab API.

This error should show up in the Unicorn logs (production.log) if you search for an HTTP 500 error:

bash-4.1$ grep -i failed gitlab-shell.log
time="2018-09-26T08:05:52+02:00" level=error msg="API call failed" body="{\"message\":\"500 Internal Server Error\"}" code=500 method=POST pid=1587 url="http://127.0.0.1:8080/api/v4/internal/allowed"
time="2018-09-26T08:45:13+02:00" level=error msg="API call failed" body="{\"message\":\"500 Internal Server Error\"}" code=500 method=POST pid=24813 url="http://127.0.0.1:8080/api/v4/internal/allowed"

Redis is a caching tool and HTTP session store that allows you to save cached data and session information from your website to an external location. This means that your website doesn’t have to calculate everything every time; instead, it can retrieve the data from the cache and load the website much faster. The user sessions are in memory even if the application goes down. Redis is a fast caching tool because it uses memory first. It has several useful advantages:

  • Everything is stored in one place, so you only have to flush one cache.
  • It is faster than Memcache. This is noticeable when using the websites of large shops.
  • Sessions are stored in memory and not in the database.
  • The backend becomes faster.

Redis is not merely a cache, but is also a data structure store. It is basically a database and should be viewed conceptually as such. With regard to its operation and how it handles data, it has more in common with a NoSQL database.

We can discover some of the basics of Redis by playing with the data structures. You can install Redis using instructions found at https://github.com/PacktPublishing/Mastering-GitLab-12/tree/master/Chapter01/InstallingRedis.md.

Start the redis-cli command-line utility, and it will connect to the local Redis server:

$redis-cli
127.0.0.1:6379>

It is not fair to view Redis as a simple hash database with key values. But still, the five data structures that are provided do actually consist of a key and a value. Let’s sum up the five data structures:

  • String: You can use the set command to write a value to Redis. In the case of a simple string, you can simply save the value in the datastore shown as follows. After setting the string value, you can retrieve the value again by issuing the get command:
$ redis-cli
127.0.0.1:6379> set mykind "Human"
OK
127.0.0.1:6379> get mykind
"Human"
127.0.0.1:6379>
  • Hash: In the same way as the string, you can set an arbitrary number of values to a key. Generally speaking, Redis treats values as a byte array and doesn’t care what they are. This make Redis very handy for representing objects. Again, with the get command, you can retrieve the values. GitLab uses this type to store web session information from users:
$ redis-cli
127.0.0.1:6379> set programs:tron '{"name": "tron","kind": "program"}'
OK
127.0.0.1:6379> get programs:tron
"{\"name\": \"tron\",\"kind\": \"program\"}"
  • List: The list type in Redis is implemented as a linked list. You can add items to the listquite quickly with rpush (right push, to the tail of the list) or lpush (left push, to the head of the list). On the other hand, accessing an item by index is not that fast because it has to search the linked list. Still, for a queue mechanism, this is a good solution.
$ redis-cli
127.0.0.1:6379> rpush specieslist human computer cyborg
(integer) 3
127.0.0.1:6379> rpop specieslist
"cyborg"
127.0.0.1:6379> rpop specieslist
"computer"
127.0.0.1:6379> rpop specieslist
"human"
127.0.0.1:6379> rpop specieslist
(nil)
  • Sets: Another datatype is the set. You add members with the sadd command. Don’t forget that these sets are unordered, so if you ask for the members with smembers, the order will mostly be different to how you entered it:
$ redis-cli
127.0.0.1:6379> sadd speciesset human computer cyborg
(integer) 3
127.0.0.1:6379> smembers speciesset
1) "computer"
2) "human"
3) "cyborg"
  • Sorted sets: Fortunately, there is an ordered set as well. It is almost the same, but one difference is that you add a score to the entry, and that will automatically score the sort order, as you can see from the following:
127.0.0.1:6379> zadd speciessortedset 1 human
(integer) 1
127.0.0.1:6379> zadd speciessortedset 2 computer
(integer) 1
127.0.0.1:6379> zadd speciessortedset 3 cyborg
(integer) 1
127.0.0.1:6379> zrange speciessortedset 0 -1
1) "human"
2) "computer"
3) "cyborg"

In the first versions of GitLab, all Git operations relied on using a local disk or network share. Gitaly is a project that tries to eliminate reliance on the Network File System (NFS). Instead of calls to a filesystem service, Gitaly provides GitLab with a system based on Remote Procedure Calls (RPCs) to access Git repositories. It is written in Go and uses gRPC Remote Procedure Call (gRPC), a cross-platform RPC framework from Google. It has been steadily developing since the beginning of 2017, and since GitLab 11.4, it can replace the need for a shared NFS filesystem.

You can find an overview of Gitaly and its place in the GitLab architecture in the following screenshot:

On a small installation, it runs in the same servers as all other components. In big clustered environments, you can set up dedicated Gitaly servers, which can be used by Gitaly clients such as the following:

  • Unicorn
  • Sidekiq
  • gitlab-workhorse
  • gitlab-shell
  • Elasticsearch indexer
  • Gitaly as a client

The source code of this project can be found here: https://gitlab.com/gitlab-org/gitaly.

You can use debugging tools that are available for Golang. But for starters, you can take a look at the log file.

For source installs, use this:

/home/git/gitaly/

For Omnibus installations, use this:

/var/log/gitlab/gitaly/current

The following is an example of a log line:

2018-09-26_13:23:40.57373 lrv162w2 gitaly: time="2018-09-26T13:23:40Z" level=info msg="finished streaming call" grpc.code=OK grpc.method=SSHUploadPack grpc.request.glRepository=project111111 grpc.request.repoPath=namespace/project-bl.git grpc.request.repoStorage=default grpc.request.topLevelGroup=hb-backend grpc.service=gitaly.SSHService grpc.time_ms=150 peer.address=@ span.kind=server system=grpc

You can see the log level is info and this is a log event that captures a Git SSH command (method=SSHUploadPack). It started a Git pack command on the server, which means it rearranged and compressed data in a repository.

To generate more verbose logging, you can set the log level to a debug in the configuration file. It is configured via a Tom’s Obvious Minimal Language (TOML) configuration file. This file is documented in the Gitaly source code repository mentioned previously.

For source installations, look here:

/home/git/gitaly/config.toml

You can change the following section and change the level:

# # One of, in order: debug, info, warn, error, fatal, panic
# # Defaults to "info"
# level = "warn"

For Omnibus installs, the following directives can be added to gitlab.rb to influence the level of monitoring of Gitaly. Set it to debug to enable debug-level logging:

gitaly['log_directory'] = "/var/log/gitlab/gitaly"
gitaly['logging_level'] = "debug"

GitLab Workhorse is a sophisticated reverse proxy that is set up in front of GitLab. Initially conceived to solve the problem of handling git-http requests, it started as a weekend project with the name gitlab-git-httpserver. The functionality was previously delivered by gitlab-grack (https://gitlab.com/gitlab-org/gitlab-grack). The main web application server, Unicorn, was not especially suited to cater for these requests, which can take a long time to finish. Handling these directly in Unicorn actually reverses the advantages that Unicorn can provide fast and scalable HTTP requests.

Workhorse was created in Golang, and was conceived by Jacob Vosmaer, one of the GitLab developers. You can read all about the process of creating it at https://about.gitlab.com/2016/04/12/a-brief-history-of-gitlab-workhorse/.

Although it was first designed to handle the Git HTTP protocol, GitLab Workhorse increasingly gained functionalities, such as these:

  • Certain static files, such as JavaScript and CSS files, are served directly.
  • It can intercept requests from Rails about opening a file. Workhorse will open the file and send the content in the response body.
  • It can intercept calls for Git Large File Storage (LFS) and insert a temporary path after preparing the file in the upload location. Git LFS is a feature where large files can be stored outside the project space in GitLab.
  • It can control WebSocket connections for Rails, such as the terminal output.

Workhorse sits behind NGINX, which handles request routing and SSL termination.

As workhorse is a Golang written application, you can use methods for this language to debug programs.

It also supports remote error logging with Sentry. To activate this feature, set the GITLAB_WORKHORSE_SENTRY_DSN environment variable.

For Omnibus installations

The following is defined in the file (/etc/gitlab/gitlab.rb):

gitlab_workhorse['env'] = {'GITLAB_WORKHORSE_SENTRY_DSN' => 'https://foobar'}

For Source installations

The following environment variable can be set in the file (/etc/default/gitlab):

export GITLAB_WORKHORSE_SENTRY_DSN='https://foobar'

Of course, the first thing to look at is the log files that are produced by this component. On an Omnibus-based GitLab installation, you can find them in /var/log/gitlab/gitlab-workhorse.

The following is an excerpt of the default log file (current):

"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.1 Safari/605.1.15" 0.478
2018-08-16_20:26:43.42795 localhost:8080 @ - - [2018/08/16:20:26:43 +0000] "GET /root/mastering-gitlab-12.git/info/refs?service=git-upload-pack HTTP/1.1" 401 26 "" "git/2.15.2 (Apple Git-101.1)" 0.066
2018-08-16_20:26:50.60861 localhost:8080 @ - - [2018/08/16:20:26:50 +0000] "POST /root/mastering-gitlab-12.git/git-upload-pack HTTP/1.1" 200 329 "" "git/2.15.2 (Apple Git-101.1)" 0.249

In the preceding log file, you see, for example, git-http operations such as git-upload-pack.

There are two database varieties available for GitLab: PostgreSQL and MySQL/MariaDB. The use of the latter is not recommended because the fast development of iterations of GitLab, as a product, have focused primarily on PostgreSQL, meaning that a number of optimizations are not available on MySQL. Furthermore, the zero-downtime method is not available when using MySQL, and neither are features such as subgroups and GEO, which will be explained later in this book.

As explained earlier, Ruby on Rails uses a so-called MVC approach. MVC is a well known architectural pattern that was developed by Trygve Reenskaug in the Smalltalk language. It was later enhanced for web applications (Model 2). The model in MVC is implemented by the ActiveRecord library, which is part of Ruby on Rails.

The authoritative source for the data model can be found here: https://gitlab.com/gitlab-org/gitlab-ee/blob/master/db/schema.rb. It is auto generated and represents the current state of the database.

The default PostgreSQL database that is included in the Omnibus package can handle workloads for up to 10,000 users. Also, if you would like to create a Disaster Recovery (DR) plan using a cold standby setup, you can use specific failover mechanisms.

A frequently used technique is to create a cold standby database (PostgreSQL DB 2) at another site, as illustrated by the following diagram:

When you want to scale or increase the number of application servers, you need to scale the database too. There are three important aspects of database scaling. Firstly, you want to be able to scale database client connections as efficiently as possible. To do this, you can use PgBouncer, which is a lightweight connection pooler.

Secondly, you want to have several database instances, one being the master node, and replicate the data from the master to the slave. In the former, DR situation, this was done by the basic built-in replication mechanism of PostgreSQL. In the current situation, a specific tool, repmgr, is used, a tool for clustering PostgreSQL and handling the failover.

Finally, a service discovery tool such as Consul can be used to detect the PostgreSQL status of each node, and update the PgBouncer service setting that determines which Postgres instance to connect to.

As you can see, there are different ways of setting up your database for GitLab. The architectures highlighted in the preceding diagram will be used in examples for building high-availability environments in Scaling the Server Infrastructure (High- Availability Setup) section of this book.

When you hit problems with PostgreSQL you can generally find the logs at /var/lib/pgsql/data but you can lookup the log_directory in postgresql.conf. On Omnibus installations, the log file is var/log/gitlab/postgresql/current.

An example of the log showing a shutdown and a startup of the database:

2019-09-09_23:02:58.04140 received TERM from runit, sending INT instead to force quit connections
2019-09-09_23:02:58.04141 LOG: received fast shutdown request
2019-09-09_23:02:58.07704 LOG: aborting any active transactions
2019-09-09_23:02:58.08152 FATAL: terminating connection due to administrator command
2019-09-09_23:02:58.08163 LOG: worker process: logical replication launcher (PID 10480) exited with exit code 1
2019-09-09_23:02:58.08458 LOG: shutting down
2019-09-09_23:02:58.12229 LOG: database system is shut down
2019-09-09_23:05:53.07284 LOG: listening on Unix socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"
2019-09-09_23:05:53.13131 LOG: database system was shut down at 2019-09-09 23:02:58 GMT2019-09-09_23:05:53.15987 LOG: database system is ready to accept connections

You can change the log settings of PostgreSQL to show more detail. For instance, you can redirect the log messages to a central server. More details on how to do this can be found here https://www.postgresql.org/docs/9.5/runtime-config-logging.html.

GitLab CI is a feature that helps perform the Continuous Integration (CI) of software components. When several developers work together using a versioning system, problems can arise when changes made by one developer break the product as a whole. The best way to make sure this happens less often, or at least early in the process, is to use integration tests more frequently, hence the name continuous.

GitLab CI was launched as a standalone project in 2013, but was later integrated into the main GitLab package. Combined with the GitLab Runner software, this feature has been very popular with developers and is an important driver of the business. It also enabled GitLab to build their product into a solution that not only does CI, but even continuous delivery up to production environments. The current product vision for GitLab is to serve as a complete DevOps life cycle product, from idea to production.

Forrester classified GitLab as a leader in CI in The Forrester Wave: Continuous Integration Tools, Q3 2017. This is shown in the following diagram:

Feedback, one of the important aspects of the Extreme Programming (XP) movement, is an important element of GitLab CI. It also serves as a way to communicate between developers.

Pipelines and build jobs are basic building blocks for a Continuous Integrations/Continuous Delivery (CI/CD) system nowadays. In GitLab, it is very easy to start a pipeline. You only need to add a .gitlab-ci.yml file to your project and then, on every commit/push to your repository, a pipeline will start. Every project has a pipeline’s overview; you can find it in the left-hand menu bar, under CI/CD:

Alternatively, you can view all jobs, by going to the Pipelines’ Jobs page, as shown in the following screenshot:

You can check the log of a job by clicking on the status of the job (for example, failed or passed). You can debug why some jobs fail and see exactly what happened:

The importance of using pipelines and jobs for CI/CD cannot be overstated. In this section, you’ve seen the basic interface to pipelines in GitLab, but in several chapters time, this will be discussed in more detail (Utilizing GitLab CI and CI Runners section).

GitLab Runners were originally developed by Kamil Trzciński in 2015. They’re now one of the most popular features of GitLab.

The initial GitLab-CI-Runner was a very simple application written in Ruby, but worked well in quite basic setups. You can think of it as a reference implementation of what a bare runner could look like.

The main problem with the old runner is that it could only run one concurrent job at a time. If you wanted to run more, you could either set up a new server or create an additional user to build jobs.

Secondly, it always ran projects on the server shell. This made it really hard to test projects using different versions of Ruby or any other dependencies. It was not stateless, meaning you had a contaminated build environment. Builds were therefore not very trustworthy. Nowadays, having a stateless and clean build environment every time is essential.

Another aspect of the old Runner that made it less favorable was that it only ran on Linux-based platforms. To make it work on macOS, a big GitLab user platform, you had to carry out additional hacking. Support for Microsoft Windows was out of the question.

Finally, there were some heavy administrative burdens. The server was hard to scale, because setting up a new server took a long time due to the dependencies you needed to take care of in order to build projects.

The newer runner is a binary that you can put on a machine of any kind. It is really easy to set up as a service and can work with multiple projects and multiple GitLab CI coordinators. It also provides support for Docker, making it really easy to set up a build environment with different versions.

Go (or Golang) is a new language (less than 10 years old). It is already widely used by some impressive parties, such as Docker (https://docker.com), Google, Kubernetes (https://kubernetes.io), and Prometheus (https://prometheus.io). Go is a versatile tool that can help you to program at a low level, close to the operating system or at a high level in a language such as Java. It is perfectly suited to creating systems software. The language was created in 2009 by R. Griesemer, R. Pike, and K.Thompson while working for Google. The latter is very famous for co-creating the first Unix implementation and the B programming language. The most important feature of the Go language is that it can compile one binary without dependencies for multiple operating systems such as Linux, macOS, the BSDs, and Windows. This also means it runs on different processor architectures (i386, amd64, ARM, and PowerPC).

A short list of the benefits of Go follows:

  • Very good standard libraries (with good optional ones available elsewhere).
  • It is very fast to develop and test in Go.
  • The culture/community chooses boring solutions over complex ones (which is good).
  • Cool tools such as Gofmt, race detector, and go vet.
  • Made for concurrency—for instance, you can use goroutines and channels.
  • Type safety—will save you many times from run-time errors and wrongly defined data types.
  • Garbage collection—while programmers who use C know how to clean up, this can still be helpful.
  • Closures or anonymous functions—enable the use of functional principles (higher-order functions).

All these characteristics make Go the perfect choice for GitLab Runners. With Go, you can create a relatively small binary that runs on a lot of platforms. It contains all that is needed to run your projects.

In a GitLab environment, jobs are being executed by the Runners. They run them as they are defined in a .gitlab-ci.yml file. The Runner itself can be running on a Virtual Machine (VM) such as VmWare (VM), VPS, a laptop, a Docker container, or in a Kubernetes cluster. Communication is one way from runner to GitLab and is mostly via an HTTP API, so that path must be accessible by the Runner.

The .yml file defines what stages your CI/CD pipeline has and what to do in each stage. This typically consists of build, test, and deploy stages.

GitLab mentions boring in its handbook as a valued way of reducing complexity; see https://about.gitlab.com/handbook/values/#efficiency.

The project can be found at https://gitlab.com/gitlab-org/gitlab-runner:

A runner can either be specific to a certain project or it can serve multiple projects in GitLab. If it serves all projects, it’s known as a Shared Runner. GitLab Runners implement a number of executors that can be used for your builds in different scenarios:

  • Shell executor: The runner simply executes a shell. The dependencies for the build have to be installed manually.
  • Docker-based executor: The runner runs from a container. This makes it easier to create clean builds because dependency management is shifted to the container image. It is also easier to create a build environment with services that need each other, such as PostgreSQL.
  • Autoscaling Docker SSH: A Docker machine creates instances with the Docker Engine to run Docker containers.
  • Kubernetes: GitLab Runner can use Kubernetes to run builds on a Kubernetes cluster.

Runners have evolved enormously over the last couple of years. GitLab itself sees them as one of the most important components of their suite. This section has given more insight into the development of this popular tool.

Toward the end of 2016 and at the start of 2017, there was a public debate in the GitLab community about whether reverting back from the cloud to bare metal would be cost-effective for GitLab.com. At the time, the filesystem used for repositories was Ceph. The performance of that distributed filesystem was not good enough to handle GitLab.com. They asked the community for advice and received a lot of feedback from people who experienced similar moves firsthand. In the end, the decision was made to stay in the cloud (https://about.gitlab.com/2017/03/02/why-we-are-not-leaving-the-cloud/). Instead, GitLab would focus on creating a solution, not on the filesystem level, but making sure that Git input/output (I/O) behavior is better managed at the application level. This can be seen as the birth of the Gitaly component. Sid Sijbrandij emphasized the importance of being a software company, not an infrastructure company.

In August 2018, GitLab migrated their cloud-based offering, GitLab.com, from Azure to Google Cloud Platform (GCP). The main reason for switching to GCP according to CEO, Sid Sijbrandij was as follows:

“Google as a public cloud, they have more experience than the other public cloud providers because they basically made a cloud for themselves […] you find that in things such as networking, where their network quality is ahead of everyone else. It’s more reliable, it has less jitter, and it’s just really, really impressive how they do that, and we’re happy to start hosting GitLab.com on that.”

It seems the move paid off; users have reported that GitLab.com is noticeably faster. Another transformation that is likely to cause further acceleration soon is the move to using Kubernetes as a container orchestrator. This is an important part of their strategy to incorporate functionality in a lot of places in GitLab besides the autoscaling of GitLab runners. GitLab’s own high-availability tool, GEO, was used to synchronize the data from one cloud to another. Running on Google’s architecture also allows GitLab to utilize object-storage for particular features as well, such as Git LFS.

In this chapter, we have learned about the people and the organization behind GitLab. Starting from the beginning, we have shown you how the project has developed over the years. We went through the core components of GitLab and how to install them. For some components, we included ways to debug the installation.

We also gave a brief introduction to GitLab CI and the client programs that interact with it, such as GitLab Runner. We showed you why this feature is so important and how it is perceived by the IT industry.

In the next chapter, we will install and configure GitLab on different kinds of systems. If you’re new to the product, prepare to be amazed!

  1. When and by whom was GitLab initially developed?
  2. How is GitLab funded?
  3. Name all the programming languages that are used in the GitLab software.
  4. Which licenses are used by GitLab?
  5. Why are they using these licenses?
  6. Name the core components of GitLab.
  7. How many offices does GitLab have?
  8. What is stored in Redis?
  9. What has Gitaly replaced?
  10. Which cloud service was chosen by GitLab to focus on in 2018?