Skip to content

GraphQL API for DevOps Adoptions segments

Adam Hegyi requested to merge 262395-devops-adoption-api into master

What does this MR do?

This MR exposes the instance level segments and defines mutations for creating, updating and deleting a segment.

The MR might look big because of the auto generated GraphQL docs.

Previous MR: !45748 (merged)

What is a Segment?

A segment (maximum 20 segments) exists on the instance level and it can contain maximum 20 groups or projects (out of scope). These segments will be periodically probed to collect various metrics about the devops adoption.

Example

Create a segment called "GitLab" which contains the following groups:

  • gitlab-org
  • gitlab-com

A periodical process (not part of this MR) will look into the configured groups and stores metrics. Examples:

  • Was there an issue created in the last 30 days? (store boolean flag: the segment adopted issues)
  • Was there an epic created in the last 30 days? (store boolean flag: the segment adopted epics)
  • ...

More info and mockups: #235421 (closed)

Database query for segments

SELECT "analytics_devops_adoption_segments".* FROM "analytics_devops_adoption_segments" ORDER BY "analytics_devops_adoption_segments"."name" ASC;

Plan:

Name is unique and we have a unique index on name.

Index Scan using index_analytics_devops_adoption_segments_on_name on analytics_devops_adoption_segments  (cost=0.15..61.35 rows=880 width=64) (actual time=0.018..0.023 rows=6 loops=1)
 Planning Time: 0.100 ms
 Execution Time: 0.050 ms
(3 rows)

Testing

How to get group GIDs?

Console: puts Group.all.map(&:to_gid)

How to generate some segments?

Console:

5.times { |i| Analytics::DevopsAdoption::Segment.create!(name: "Segment #{i}", segment_selections_attributes: Group.all.shuffle.take(rand(5) + 1).map { |group| { group_id: group.id } })}

To test the mutations locally, navigate to: http://localhost:3000/-/graphql-explorer

Make sure you're logged in as admin.

Creating a Segment:

mutation {
  createDevopsAdoptionSegment(input: {name:"mySegment", groupIds: ["gid://gitlab/Group/22", "gid://gitlab/Group/21"]}) {
    segment {
      id
      name
      groups {
        nodes {
          name
          id
          webUrl
        }
      }
    }
    errors   
  }
}

Updating a segment:

mutation updateSegment {
  updateDevopsAdoptionSegment(input: {id: "gid://gitlab/Analytics::DevopsAdoption::Segment/2", name:"RenamedSegment", groupIds: ["gid://gitlab/Group/23"]}) {
    segment {
      id
      name
      groups {
        nodes {
          name
          id
          webUrl
        }
      }
    }
    errors   
  }
}

Deleting a segment:

mutation deleteSegment {
  deleteDevopsAdoptionSegment(input: {id: "gid://gitlab/Analytics::DevopsAdoption::Segment/2"}) {
    errors
  }
}

Listing segments:

query getSegments {
  devopsAdoptionSegments {
    nodes {
      id
      name
      groups {
        nodes {
          name
          id
          webUrl
        }
      }
    }
  }
}

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #262395 (closed)

Edited by Adam Hegyi

Merge request reports