Skip to content

Add Agent graphql hasRemoteDevelopmentAgentConfig filter

Chad Woolley requested to merge caw-filter-remote-dev-agents into master

What does this MR do and why?

Resolves Add graphql finder to filter agents with remote... (#407641 - closed)

Adds Agent graphql hasRemoteDevelopmentAgentConfig filter

  • For use in Remote Development UI

Screenshots or screen recordings

before after
Screenshot_2023-05-10_at_1.38.05_AM Screenshot_2023-05-10_at_1.37.22_AM

Example GraphQL Query as used by UI

Actual GraphQL query used from UI, with hasRemoteDevelopmentAgentConfig = true:

query getGroupClusterAgents(
  $groupFullPath: ID!,
  $hasRemoteDevelopmentAgentConfig: Boolean
) {
  group(fullPath: $groupFullPath) {
    id
    clusterAgents(hasRemoteDevelopmentAgentConfig: $hasRemoteDevelopmentAgentConfig) {
      nodes {
        id
        name 
        project {
          id
          nameWithNamespace
        }
      }
    }
  }
}

Database Query Plans

Clusters::Agent.with_remote_development_agent_config

NOTE: This is the only scenario used by the current UI code, we only need to use hasRemoteDevelopmentAgentConfig = true.

Development Rails console output:

  Clusters::Agent Load (0.9ms)  SELECT "cluster_agents".* FROM "cluster_agents" INNER JOIN "remote_development_agent_configs" ON "remote_development_agent_configs"."cluster_agent_id" = "cluster_agents"."id" WHERE "cluster_agents"."project_id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."namespace_id" IN (SELECT namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)] AS id FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND (traversal_ids @> ('{97}')))) ORDER BY "cluster_agents"."name" ASC, "cluster_agents"."id" DESC LIMIT 101 /*application:web,correlation_id:01H06G5HJN6R95VF331ZWY0Z13,endpoint_id:GraphqlController#execute,db_config_name:main,line:/lib/gitlab/graphql/pagination/keyset/connection.rb:122:in `block in limited_nodes'*/
  ↳ lib/gitlab/graphql/pagination/keyset/connection.rb:122:in `block in limited_nodes'

SQL Query (with production gitlab-org namespace ID 9970):

SELECT
    "cluster_agents".*
FROM
    "cluster_agents"
    INNER JOIN "remote_development_agent_configs" ON "remote_development_agent_configs"."cluster_agent_id" = "cluster_agents"."id"
WHERE
    "cluster_agents"."project_id" IN (
        SELECT
            "projects"."id"
        FROM
            "projects"
        WHERE
            "projects"."namespace_id" IN (
                SELECT
                    namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)] AS id
                FROM
                    "namespaces"
                WHERE
                    "namespaces"."type" = 'Group'
                    AND (traversal_ids @> ('{9970}'))))
    ORDER BY
        "cluster_agents"."name" ASC,
        "cluster_agents"."id" DESC
    LIMIT 101

Query explain plan command link: https://console.postgres.ai/shared/3f322f1c-4910-4618-b5e1-de2f71dd5d17

Clusters::Agent.without_remote_development_agent_config

NOTE: There is no actual usage of this query in the codebase with the boolean flag being false, because there's no need for it, but it is possible from the graphQL API. I.e. there's no actual usage of hasRemoteDevelopmentAgentConfig = false

Development Rails console output:

  SQL (1.0ms)  SELECT "cluster_agents"."id" AS t0_r0, "cluster_agents"."created_at" AS t0_r1, "cluster_agents"."updated_at" AS t0_r2, "cluster_agents"."project_id" AS t0_r3, "cluster_agents"."name" AS t0_r4, "cluster_agents"."created_by_user_id" AS t0_r5, "cluster_agents"."has_vulnerabilities" AS t0_r6, "remote_development_agent_config"."id" AS t1_r0, "remote_development_agent_config"."created_at" AS t1_r1, "remote_development_agent_config"."updated_at" AS t1_r2, "remote_development_agent_config"."cluster_agent_id" AS t1_r3, "remote_development_agent_config"."enabled" AS t1_r4, "remote_development_agent_config"."dns_zone" AS t1_r5 FROM "cluster_agents" LEFT OUTER JOIN "remote_development_agent_configs" "remote_development_agent_config" ON "remote_development_agent_config"."cluster_agent_id" = "cluster_agents"."id" WHERE "cluster_agents"."project_id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."namespace_id" IN (SELECT namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)] AS id FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND (traversal_ids @> ('{97}')))) AND "remote_development_agent_config"."cluster_agent_id" IS NULL ORDER BY "cluster_agents"."name" ASC, "cluster_agents"."id" DESC LIMIT 101 /*application:web,correlation_id:01H06GCDTTPJPPFKMSCNVVY2KQ,endpoint_id:GraphqlController#execute,db_config_name:main,line:/lib/gitlab/graphql/pagination/keyset/connection.rb:122:in `block in limited_nodes'*/

SQL Query (with production gitlab-org namespace ID 9970):

SELECT
    "cluster_agents"."id" AS t0_r0,
    "cluster_agents"."created_at" AS t0_r1,
    "cluster_agents"."updated_at" AS t0_r2,
    "cluster_agents"."project_id" AS t0_r3,
    "cluster_agents"."name" AS t0_r4,
    "cluster_agents"."created_by_user_id" AS t0_r5,
    "cluster_agents"."has_vulnerabilities" AS t0_r6,
    "remote_development_agent_config"."id" AS t1_r0,
    "remote_development_agent_config"."created_at" AS t1_r1,
    "remote_development_agent_config"."updated_at" AS t1_r2,
    "remote_development_agent_config"."cluster_agent_id" AS t1_r3,
    "remote_development_agent_config"."enabled" AS t1_r4,
    "remote_development_agent_config"."dns_zone" AS t1_r5
FROM
    "cluster_agents"
    LEFT OUTER JOIN "remote_development_agent_configs" "remote_development_agent_config" ON "remote_development_agent_config"."cluster_agent_id" = "cluster_agents"."id"
WHERE
    "cluster_agents"."project_id" IN (
        SELECT
            "projects"."id"
        FROM
            "projects"
        WHERE
            "projects"."namespace_id" IN (
                SELECT
                    namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)] AS id
                FROM
                    "namespaces"
                WHERE
                    "namespaces"."type" = 'Group'
                    AND (traversal_ids @> ('{9970}'))))
        AND "remote_development_agent_config"."cluster_agent_id" IS NULL
    ORDER BY
        "cluster_agents"."name" ASC,
        "cluster_agents"."id" DESC
    LIMIT 101

Query plan command link: https://console.postgres.ai/shared/31fe401b-afd3-470e-9a2a-f84d4ba4f643

How to set up and validate locally

  1. Make agents in a project with and without a remote development agent config
  2. Create a workspace, see that the agent without a config doesn't show up in the dropdown.

See https://gitlab.com/gitlab-org/remote-development/gitlab-remote-development-docs for more context on the Remote Development feature.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Chad Woolley

Merge request reports