Commit 50ad2015 authored by Markus Koller's avatar Markus Koller

Merge branch '322605-fix-agentk-metadata' into 'master'

Add GraphQL type for agent metadata

See merge request gitlab-org/gitlab!70343
parents 4c04855e e06c6cf6
...@@ -7637,6 +7637,19 @@ Configuration details for an Agent. ...@@ -7637,6 +7637,19 @@ Configuration details for an Agent.
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| <a id="agentconfigurationagentname"></a>`agentName` | [`String`](#string) | Name of the agent. | | <a id="agentconfigurationagentname"></a>`agentName` | [`String`](#string) | Name of the agent. |
### `AgentMetadata`
Information about a connected Agent.
#### Fields
| Name | Type | Description |
| ---- | ---- | ----------- |
| <a id="agentmetadatacommit"></a>`commit` | [`String`](#string) | Agent version commit. |
| <a id="agentmetadatapodname"></a>`podName` | [`String`](#string) | Name of the pod running the Agent. |
| <a id="agentmetadatapodnamespace"></a>`podNamespace` | [`String`](#string) | Namespace of the pod running the Agent. |
| <a id="agentmetadataversion"></a>`version` | [`String`](#string) | Agent version tag. |
### `AlertManagementAlert` ### `AlertManagementAlert`
Describes an alert from the project's Alert Management. Describes an alert from the project's Alert Management.
...@@ -8551,7 +8564,7 @@ Connection details for an Agent. ...@@ -8551,7 +8564,7 @@ Connection details for an Agent.
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| <a id="connectedagentconnectedat"></a>`connectedAt` | [`Time`](#time) | When the connection was established. | | <a id="connectedagentconnectedat"></a>`connectedAt` | [`Time`](#time) | When the connection was established. |
| <a id="connectedagentconnectionid"></a>`connectionId` | [`BigInt`](#bigint) | ID of the connection. | | <a id="connectedagentconnectionid"></a>`connectionId` | [`BigInt`](#bigint) | ID of the connection. |
| <a id="connectedagentmetadata"></a>`metadata` | [`JSON`](#json) | Information about the Agent. | | <a id="connectedagentmetadata"></a>`metadata` | [`AgentMetadata`](#agentmetadata) | Information about the Agent. |
### `ContainerExpirationPolicy` ### `ContainerExpirationPolicy`
......
...@@ -17,8 +17,8 @@ module Types ...@@ -17,8 +17,8 @@ module Types
null: true, null: true,
description: 'ID of the connection.' description: 'ID of the connection.'
field :metadata, # rubocop:disable Graphql/JSONType field :metadata,
GraphQL::Types::JSON, Types::Kas::AgentMetadataType,
method: :agent_meta, method: :agent_meta,
null: true, null: true,
description: 'Information about the Agent.' description: 'Information about the Agent.'
......
# frozen_string_literal: true
module Types
module Kas
# rubocop: disable Graphql/AuthorizeTypes
class AgentMetadataType < BaseObject
graphql_name 'AgentMetadata'
description 'Information about a connected Agent'
field :version,
GraphQL::Types::String,
null: true,
description: 'Agent version tag.'
field :commit,
GraphQL::Types::String,
method: :commit_id,
null: true,
description: 'Agent version commit.'
field :pod_namespace,
GraphQL::Types::String,
null: true,
description: 'Namespace of the pod running the Agent.'
field :pod_name,
GraphQL::Types::String,
null: true,
description: 'Name of the pod running the Agent.'
end
# rubocop: enable Graphql/AuthorizeTypes
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Types::Kas::AgentMetadataType do
include GraphqlHelpers
let(:fields) { %i[version commit pod_namespace pod_name] }
it { expect(described_class.graphql_name).to eq('AgentMetadata') }
it { expect(described_class.description).to eq('Information about a connected Agent') }
it { expect(described_class).to have_graphql_fields(fields) }
end
...@@ -77,4 +77,33 @@ RSpec.describe 'Project.cluster_agents' do ...@@ -77,4 +77,33 @@ RSpec.describe 'Project.cluster_agents' do
end.to issue_same_number_of_queries_as { post_graphql(query, current_user: current_user, variables: [first.with(1)]) } end.to issue_same_number_of_queries_as { post_graphql(query, current_user: current_user, variables: [first.with(1)]) }
end end
end end
context 'selecting connections' do
let(:agent_meta) { double(version: '1', commit_id: 'abc', pod_namespace: 'namespace', pod_name: 'pod') }
let(:connected_agent) { double(agent_id: agents.first.id, connected_at: 123456, connection_id: 1, agent_meta: agent_meta) }
let(:metadata_fields) { query_graphql_field(:metadata, {}, [:version, :commit, :pod_namespace, :pod_name], 'AgentMetadata') }
let(:cluster_agents_fields) { [:id, query_nodes(:connections, [:connection_id, :connected_at, metadata_fields])] }
before do
allow(Gitlab::Kas::Client).to receive(:new).and_return(double(get_connected_agents: [connected_agent]))
end
it 'can retrieve connections and agent metadata' do
post_graphql(query, current_user: current_user)
connection = graphql_data_at(:project, :cluster_agents, :nodes, :connections, :nodes).first
expect(connection).to include({
'connectionId' => connected_agent.connection_id.to_s,
'connectedAt' => Time.at(connected_agent.connected_at),
'metadata' => {
'version' => agent_meta.version,
'commit' => agent_meta.commit_id,
'podNamespace' => agent_meta.pod_namespace,
'podName' => agent_meta.pod_name
}
})
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment