Skip to content

Add GraphQL type and resolver for agent activity events

Tiger Watson requested to merge 340364-agent-activity-events-graphql into master

What does this MR do and why?

Adds GraphQL type & resolver for activity events related to an Agent. These will be used by the frontend to create an activity stream.

Screenshots or screen recordings

GraphQL query:

{
  project(fullPath: "path/to/agent-config") {    
    clusterAgent(name:"my-agent") {
      name
      activityEvents {
        nodes {
          kind
          level
          recordedAt
          agentToken {
            name
          }
          user {
            name
          }
        }
      }
    }
  }
}

Response:

{
  "data": {
    "project": {
      "clusterAgent": {
        "name": "my-agent",
        "activityEvents": {
          "nodes": [
            {
              "kind": "token_created",
              "level": "info",
              "recordedAt": "2021-11-24T00:36:38Z",
              "agentToken": {
                "name": "new token"
              },
              "user": {
                "name": "Administrator"
              }
            }
          ]
        }
      }
    }
  }
}

How to set up and validate locally

  1. Create an Agent record: Clusters::Agent.create!(project: <project>, name: 'example-agent')
  2. Create an Agent token: Clusters::AgentTokens::CreateService.new(container: <project>, current_user: <user>, params: { agent_id: <agent-id>, name: 'example-token' }).execute
  3. From the GraphQL explorer, execute the above query.

MR acceptance checklist

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

Related to #340364 (closed)

Edited by Tiger Watson

Merge request reports