

# Connect to a GitLab data source
<a name="gitlab-AMG-datasource"></a>

The GitLab data source allows you to keep track of detailed GitLab statistics, such as top contributors, commits per day, or deployments per day. You can also use template variables, such as projects, to set up filters for your dashboards. You can combine data from the GitLab API with data from other sources.

**Note**  
This data source is for Grafana Enterprise only. For more information, see [Manage access to Enterprise plugins](upgrade-to-enterprise-plugins.md).  
Additionally, in workspaces that support version 9 or newer, this data source might require you to install the appropriate plugin. For more information, see [Extend your workspace with plugins](grafana-plugins.md).

## Known limitations
<a name="gitlab-known-limitations"></a>

Alerting is not supported yet on this plugin because transformations are not supported in alert queries and transformations is the only way to obtain meaningful aggregate metrics from GitLab API raw data.

## Adding the data source
<a name="gitlab-adding-the-data-source"></a>

1.  Open the Grafana console in the Amazon Managed Grafana workspace and make sure you are logged in. 

1.  In the side menu under **Configuration** (the gear icon), choose **Data Sources**. 

1.  Choose **Add data source**. 
**Note**  
 If you don't see the **Data Sources** link in your side menu, it means that your current user does not have the `Admin` role. 

1.  Select **GitLab** from the list of data sources. 

1. Enter the following information:
   + For **Name**, enter a name for this GitLab data source.
   + For **URL**, enter the root URL for your GitLab instance, such as **https://gitlab.com/api/v4**.
   + For **Access token**, enter your GitLab personal access token.

## Query the GitLab data source
<a name="gitlab-query"></a>

From the GitLab Query Editor you can select different resource types, such as commits, issues, or releases.

**Filter and view projects**

1.  From the dropdown menu, choose **Projects**. 

1.  (Optional) Filter by the projects that you own. 

1.  Use the dropdown and select **Yes** or **No** to filter the results. 
**Note**  
 Fetching all the projects **Owned = No** can take a long time. 

**Filter and view commits**

1.  From the dropdown menu, choose **Commits**. 

1.  Use the input field to add the project ID. 

1.  (Optional) To filter by branch/tag use the input field to add a branch/tag reference. 

**Filter and view issues**

1.  From the dropdown menu, choose **Issues**. 

1.  Use the input field to add the project ID. 

1.  (Optional) To filter by title/description, use the input field to search issues based on their **title** and **description**. 

**View releases**

1.  From the dropdown menu, choose **Deployments**. 

1.  Use the input field to add the project ID. 

1.  (Optional) To filter by environment/status, use the input fields. The **status** attribute can be one of the following values: `created`, `running`, `success`, `failed`, or `canceled`. 

**View labels**

1.  From the dropdown menu, choose **Labels**. 

1.  Use the input field to add the project ID. 

## Templates and variables
<a name="gitlab-templates"></a>

To add a new GitLab query variable, see [Adding a query variable](variables-types.md#add-a-query-variable). Use your GitLab data source as the data source. Choose a resource type: **Releases**, **Projects**, or **Labels**.

To get a dynamic list of projects, labels, and so on to choose from, create a Query type variable. Query type variables use the GitLab Query Editor to query and return Projects, Labels, and so on. The following example creates a Project variable to parameterize your queries

**Create a Project variable to parameterize your queries**

1.  Add a variable of type **Query** named **project**. 

1.  Select your GitLab data source and refresh **On Dashboard Load**. 

1.  Select the **Projects** resource type, **Yes** for **Owned**, **name** for **display field** and **id** for **value field **. 

1. Choose **Update** to add the variable to the dashboard.

1. Add a new panel to the dashboard and use **\$1project** as the project ID.

   Now, when choosing from the dropdown, you get the results that belong to that project.

## Using transformations from Grafana to answer common questions
<a name="gitlab-transformations"></a>

Now that you can perform basic GitLab queries to find commits, issues, etc, you can use Transformations to visualize, aggregate, group, and join datasets, along with many other types of transformations to transform simple results into answers for complex questions. Below are a few common questions and how to use transformations to answer them.

**How many commits/issues/deployments per day in my project?**

1.  Add a query. Select **Commits** for the resource type and add the project ID. 

1.  Add a new **Group by** transformation: for **Group by**, select **created\$1at\$1date** and then calculate **(Count)=id** 

1. Choose the **Graph** visualization.

**What is the average time to close issues in my project?**

1.  Add a query. Select **Issues** for the resource type and add the project ID. 

1.  Add a new **Add field from calculation** transformation: for **Mode**, select **Binary Operation**, for **Operation**, select **closed\$1at = created\$1at** and for **Alias** choose **resolution\$1time**. 

1.  Add a new **Add field from calculation** transformation: for **Mode**, select **Binary Operation**, for **Operation**, select **resolution\$1time / 86400000** and for **Alias** choose **resolution\$1time**. 

   For **Replace all fields**, choose **True**.

1. Choose the **Stat** visualization.
   + Show = Calculate
   + Calculation = Mean
   + Fields = **resolution\$1time**