1. Insights
- View your project’s Insights
 - Configure your Insights
 - Permissions
 - Writing your 
.gitlab/insights.yml - Configuration parameters
 
2. Insights
Introduced in GitLab Ultimate 12.0.
配置对您的项目至关重要的见解,以探索数据,例如分类诊断,在给定期间内创建/关闭的问题,合并请求的平均合并时间等等.
注意:此功能在组级别也可用 .
2.1. View your project’s Insights
您可以通过点击左侧栏中的Analytics(分析)> Insights链接来访问项目的 Insights:
2.2. Configure your Insights
使用项目中名为.gitlab/insights.yml的 YAML 文件配置.gitlab/insights.yml . 该文件将在项目的"见解"页面中使用.
有关此文件内容的详细信息,请参见下面的编写.gitlab/insights.yml .
注意:一旦创建了配置文件,您也可以将其用于项目的 group .注意:如果项目没有任何配置文件,则将尽可能尝试使用组配置. 如果该组没有任何配置,将使用默认配置.
2.3. Permissions
如果您有权查看项目,则可以查看其见解.
注意:您无法访问的问题或合并请求(因为您无法访问它们所属的项目,或者因为它们是机密的)会从 Insights 图表中过滤掉.
您也可以查阅组权限表 .
2.4. Writing your .gitlab/insights.yml
.gitlab/insights.yml文件定义了将在项目或组的每个 Insights 页面中显示的 Insights 图表的结构和顺序.
每个页面都有一个唯一的键以及一组要获取和显示的图表.
例如,这是 Insights 的单个定义,它将显示一个带有一个图表的页面:
bugsCharts:
  title: "Charts  for  bugs"
  charts:
    - title: "Monthly  bugs  created"
      description: "Open  bugs  created  per  month"
      type: bar
      query:
        issuable_type: issue
        issuable_state: opened
        filter_labels:
          - bug
        group_by: month
        period_limit: 24 
每个图表定义均由键值对组成的哈希组成.
例如,这是单个图表定义:
- title: "Monthly  bugs  created"
  description: "Open  bugs  created  per  month"
  type: bar
  query:
    issuable_type: issue
    issuable_state: opened
    filter_labels:
      - bug
    group_by: month
    period_limit: 24 
2.5. Configuration parameters
图表被定义为定义图表行为的参数列表.
下表列出了图表的可用参数:
| Keyword | Description | 
|---|---|
| [`title`](#title) | 图表标题. 这将显示在"见解"页面上. | 
| [`description`](#description) | 单个图表的描述. 这将显示在相关图表上方. | 
| [`type`](#type) | 图表类型: `bar` , `line`或`stacked-bar` . | 
| [`query`](#query) | 散列,用于定义要成为图表一部分的问题/合并请求的条件. | 
2.6. Parameter details
以下是用于配置 Insights 图表的参数的详细说明.
2.6.1. title
title是图表的标题,它将显示在 Insights 页面上. 例如:
monthlyBugsCreated:
  title: "Monthly  bugs  created" 
2.6.2. description
description文字显示在图表上方,但标题下方. 它用于提供有关图表的更多详细信息,例如:
monthlyBugsCreated:
  title: "Monthly  bugs  created"
  description: "Open  bugs  created  per  month" 
2.6.3. type
type是图表类型.
例如:
monthlyBugsCreated:
  title: "Monthly  bugs  created"
  type: bar 
Supported values are:
| Name | Example | 
|---|---|
| `bar` | [](img/insights_example_bar_chart.png) | 
| `bar` (time series, i.e. when `group_by` is used) | [](img/insights_example_bar_time_series_chart.png) | 
| `line` | [](img/insights_example_line_chart.png) | 
| `stacked-bar` | [](img/insights_example_stacked_bar_chart.png) | 
2.6.4. query
query允许定义条件/合并请求成为图表的一部分.
Example:
monthlyBugsCreated:
  title: "Monthly  bugs  created"
  description: "Open  bugs  created  per  month"
  type: bar
  query:
    issuable_type: issue
    issuable_state: opened
    filter_labels:
      - bug
    collection_labels:
      - S1
      - S2
      - S3
      - S4
    group_by: week
    period_limit: 104 
query.issuable_type
定义要为其创建图表的"可发行"的类型.
支持的值为:
issue:图表将显示问题的数据.merge_request:图表将显示合并请求的数据.
query.issuable_state
按查询的"可发行"状态过滤.
默认情况下,将使用opened状态过滤器.
支持的值为:
opened:未解决问题/合并请求.closed:已关闭未解决的问题/合并请求.locked:已锁定讨论的问题/合并请求.merged:合并的合并请求.all:在所有状态下发出/合并请求
query.filter_labels
按应用于查询的"可发行"的标签过滤.
默认情况下,不应用标签过滤器. 必须将所有定义的标签应用于"可发行",才能对其进行选择.
Example:
monthlyBugsCreated:
  title: "Monthly  regressions  created"
  type: bar
  query:
    issuable_type: issue
    issuable_state: opened
    filter_labels:
      - bug
      - regression 
query.collection_labels
通过配置的标签将"可发行"分组.
默认情况下,不会进行分组. 使用此关键字时,需要将type设置为line或stacked-bar .
Example:
weeklyBugsBySeverity:
  title: "Weekly  bugs  by  severity"
  type: stacked-bar
  query:
    issuable_type: issue
    issuable_state: opened
    filter_labels:
      - bug
    collection_labels:
      - S1
      - S2
      - S3
      - S4 
query.group_by
定义图表的 X 轴.
支持的值为:
day:day组数据.week:week组数据.month:month组数据.
query.period_limit
定义过去查询"可耗材"的距离.
该单位与您定义的query.group_by有关. 例如,如果您定义了query.group_by: 'day'则query.period_limit: 365意思是"收集并显示最近 365 天的数据".
默认情况下,将根据您定义的query.group_by应用默认值.
| `query.group_by` | 默认值 | 
|---|---|
| `day` | 30 | 
| `week` | 4 | 
| `month` | 12 | 
query.period_field
定义用于将"可耗材"分组的时间戳字段.
支持的值为:
created_at(默认):使用created_at字段对数据进行分组.closed_at:使用closed_at字段对数据进行closed_at(仅针对问题).merged_at:使用merged_at字段对数据进行merged_at(仅适用于合并请求).
period_field自动设置为:
closed_atifquery.issuable_stateisclosedmerged_atifquery.issuable_stateismergedcreated_atotherwise
注意:在解决此错误之前,您可能会看到created_at代替merged_at . 将使用created_at代替.
2.6.5. projects
Introduced in GitLab Ultimate 12.4.
您可以限制从以下位置查询"可耗材"的位置:
- 如果
.gitlab/insights.yml用于一组的见解 ,有projects,你可以限制要查询的项目. 默认情况下,将使用该组下的所有项目. - 如果将
.gitlab/insights.yml用于项目的见解,则指定任何其他项目均不会产生任何结果. 默认情况下,将使用项目本身. 
projects.only
projects.only选项指定应从中查询"可发行物品"的项目.
在以下情况下,此处列出的项目将被忽略:
- 它们不存在.
 - 当前用户没有足够的权限来读取它们.
 - 他们不在小组中.
 
在以下insights.yml示例中,我们指定将在其中使用查询的项目. 设置小组的见解时,此示例非常有用:
monthlyBugsCreated:
  title: "Monthly  bugs  created"
  description: "Open  bugs  created  per  month"
  type: bar
  query:
    issuable_type: issue
    issuable_state: opened
    filter_labels:
      - bug
  projects:
    only:
      - 3                         # You can use the project ID
      - groupA/projectA           # Or full project path
      - groupA/subgroupB/projectC # Projects in subgroups can be included
      - groupB/project            # Projects outside the group will be ignored 
2.7. Complete example
.projectsOnly: &projectsOnly
  projects:
    only:
      - 3
      - groupA/projectA
      - groupA/subgroupB/projectC
bugsCharts:
  title: "Charts  for  bugs"
  charts:
    - title: "Monthly  bugs  created"
      description: "Open  bugs  created  per  month"
      type: bar
      <<: *projectsOnly
      query:
        issuable_type: issue
        issuable_state: opened
        filter_labels:
          - bug
        group_by: month
        period_limit: 24
    - title: "Weekly  bugs  by  severity"
      type: stacked-bar
      <<: *projectsOnly
      query:
        issuable_type: issue
        issuable_state: opened
        filter_labels:
          - bug
        collection_labels:
          - S1
          - S2
          - S3
          - S4
        group_by: week
        period_limit: 104
    - title: "Monthly  bugs  by  team"
      type: line
      <<: *projectsOnly
      query:
        issuable_type: merge_request
        issuable_state: opened
        filter_labels:
          - bug
        collection_labels:
          - Manage
          - Plan
          - Create
        group_by: month
        period_limit: 24 
                                
                                
