Gitlab to Redshift

This page provides you with instructions on how to extract data from Gitlab and load it into Redshift. (If this manual process sounds lengthy, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

Pulling Data Out of Gitlab

First thing you need to do is get your data out of Gitlab.  That can be done by making calls to Gitlab’s API. The full documentation for the API can be found hereGitlab’s API offers access to data endpoints like branches, commits, and issues. Using methods outlined in the API documentation, you can retrieve the data you’d like to move to Redshift.

Sample Gitlab Data

This is an example of what the data looks like from the commits endpoint.

[
  {
    "id": "ed899a2f4b50b4370feeea94676502b42383c746",
    "short_id": "ed899a2f4b5",
    "title": "Replace sanitize with escape once",
    "author_name": "Dmitriy Zaporozhets",
    "author_email": "dzaporozhets@sphereconsultinginc.com",
    "authored_date": "2012-09-20T11:50:22+03:00",
    "committer_name": "Administrator",
    "committer_email": "admin@example.com",
    "committed_date": "2012-09-20T11:50:22+03:00",
    "created_at": "2012-09-20T11:50:22+03:00",
    "message": "Replace sanitize with escape once",
    "parent_ids": [
      "6104942438c14ec7bd21c6cd5bd995272b3faff6"
    ]
  },
  {
    "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
    "short_id": "6104942438c",
    "title": "Sanitize for network graph",
    "author_name": "randx",
    "author_email": "dmitriy.zaporozhets@gmail.com",
    "committer_name": "Dmitriy",
    "committer_email": "dmitriy.zaporozhets@gmail.com",
    "created_at": "2012-09-20T09:06:12+03:00",
    "message": "Sanitize for network graph",
    "parent_ids": [
      "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
    ]
  }
]

Preparing Gitlab Data for Redshift

Now that you have the data you’re looking for, you’ll need to map all those data fields into a schema that can be inserted into your Redshift database. For each value in the response, you need to identify a predefined data type (i.e. INTEGER, DATETIME, etc.) and build a table that can receive them.

Check out the Stitch Gitlab Documentation to get a good sense of what fields and data types will be provided by each endpoint. Once you have identified all of the columns you will want to insert, use the CREATE TABLE statement in Redshift to build a table that will receive all of this data.

Inserting Gitlab Data into Redshift

It may seem like the easiest way to add your data is to build tried-and-true INSERT statements that add data to your Redshift table row-by-row. If you have any experience with SQL, this will be your first reaction.  It will work, but isn’t the most efficient way to get the job done.

Redshift offers some helpful documentation for how to best bulk insert data into new tables. The COPY command is particularly useful for this task, as it allows you to insert multiple rows without needing to build individual INSERT statements for each row.

If you cannot use COPY, it might help to use PREPARE to create a an INSERT statement, and then use EXECUTE as many times as required. This avoids some of the overhead of repeatedly parsing and planning INSERT.

Easier and Faster Alternatives

If you have all the skills necessary to go through this process, you  might have other projects that you need to be focusing on.

Luckily, powerful tools like Stitch were built to solve this problem automatically. With just a few clicks, Stitch starts extracting your Gitlab data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Redshift data warehouse.