Commit 194acaca authored by Alex Ives's avatar Alex Ives

Add GraphQL for Terraform States

- Add terraform state registry finder
- Add terraform state resolver
- Add terraform state registry type
- Use package_file specific feature flag for it's graphql

Relates to https://gitlab.com/gitlab-org/gitlab/issues/220956
parent 5cad762b
......@@ -5839,7 +5839,7 @@ type GeoNode {
name: String
"""
Package file registries of the GeoNode. Available only when feature flag `geo_self_service_framework` is enabled
Package file registries of the GeoNode. Available only when feature flag `geo_package_file_replication` is enabled
"""
packageFileRegistries(
"""
......@@ -5918,6 +5918,37 @@ type GeoNode {
"""
syncObjectStorage: Boolean
"""
Find terraform state registries on this Geo node. Available only when feature
flag `geo_terraform_state_replication` is enabled
"""
terraformStateRegistries(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Filters registries by their ID
"""
ids: [ID!]
"""
Returns the last _n_ elements from the list.
"""
last: Int
): TerraformStateRegistryConnection
"""
The user-facing URL for this Geo node
"""
......@@ -15347,6 +15378,86 @@ type TaskCompletionStatus {
count: Int!
}
"""
Represents the sync and verification state of a terraform state
"""
type TerraformStateRegistry {
"""
Timestamp when the TerraformStateRegistry was created
"""
createdAt: Time
"""
ID of the TerraformStateRegistry
"""
id: ID!
"""
Error message during sync of the TerraformStateRegistry
"""
lastSyncFailure: String
"""
Timestamp of the most recent successful sync of the TerraformStateRegistry
"""
lastSyncedAt: Time
"""
Timestamp after which the TerraformStateRegistry should be resynced
"""
retryAt: Time
"""
Number of consecutive failed sync attempts of the TerraformStateRegistry
"""
retryCount: Int
"""
Sync state of the TerraformStateRegistry
"""
state: RegistryState
"""
ID of the TerraformState
"""
terraformStateId: ID!
}
"""
The connection type for TerraformStateRegistry.
"""
type TerraformStateRegistryConnection {
"""
A list of edges.
"""
edges: [TerraformStateRegistryEdge]
"""
A list of nodes.
"""
nodes: [TerraformStateRegistry]
"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}
"""
An edge in a connection.
"""
type TerraformStateRegistryEdge {
"""
A cursor for use in pagination.
"""
cursor: String!
"""
The item at the end of the edge.
"""
node: TerraformStateRegistry
}
"""
Represents a requirement test report.
"""
......
......@@ -16339,7 +16339,7 @@
},
{
"name": "packageFileRegistries",
"description": "Package file registries of the GeoNode. Available only when feature flag `geo_self_service_framework` is enabled",
"description": "Package file registries of the GeoNode. Available only when feature flag `geo_package_file_replication` is enabled",
"args": [
{
"name": "ids",
......@@ -16539,6 +16539,77 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "terraformStateRegistries",
"description": "Find terraform state registries on this Geo node. Available only when feature flag `geo_terraform_state_replication` is enabled",
"args": [
{
"name": "ids",
"description": "Filters registries by their ID",
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
}
},
"defaultValue": null
},
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "TerraformStateRegistryConnection",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "url",
"description": "The user-facing URL for this Geo node",
......@@ -45302,6 +45373,251 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "TerraformStateRegistry",
"description": "Represents the sync and verification state of a terraform state",
"fields": [
{
"name": "createdAt",
"description": "Timestamp when the TerraformStateRegistry was created",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "id",
"description": "ID of the TerraformStateRegistry",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "lastSyncFailure",
"description": "Error message during sync of the TerraformStateRegistry",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "lastSyncedAt",
"description": "Timestamp of the most recent successful sync of the TerraformStateRegistry",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "retryAt",
"description": "Timestamp after which the TerraformStateRegistry should be resynced",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "retryCount",
"description": "Number of consecutive failed sync attempts of the TerraformStateRegistry",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "state",
"description": "Sync state of the TerraformStateRegistry",
"args": [
],
"type": {
"kind": "ENUM",
"name": "RegistryState",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "terraformStateId",
"description": "ID of the TerraformState",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "TerraformStateRegistryConnection",
"description": "The connection type for TerraformStateRegistry.",
"fields": [
{
"name": "edges",
"description": "A list of edges.",
"args": [
],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "TerraformStateRegistryEdge",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "nodes",
"description": "A list of nodes.",
"args": [
],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "TerraformStateRegistry",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "pageInfo",
"description": "Information to aid in pagination.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PageInfo",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "TerraformStateRegistryEdge",
"description": "An edge in a connection.",
"fields": [
{
"name": "cursor",
"description": "A cursor for use in pagination.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "node",
"description": "The item at the end of the edge.",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "TerraformStateRegistry",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "TestReport",
......@@ -2274,6 +2274,21 @@ Completion status of tasks
| `completedCount` | Int! | Number of completed tasks |
| `count` | Int! | Number of total tasks |
## TerraformStateRegistry
Represents the sync and verification state of a terraform state
| Name | Type | Description |
| --- | ---- | ---------- |
| `createdAt` | Time | Timestamp when the TerraformStateRegistry was created |
| `id` | ID! | ID of the TerraformStateRegistry |
| `lastSyncFailure` | String | Error message during sync of the TerraformStateRegistry |
| `lastSyncedAt` | Time | Timestamp of the most recent successful sync of the TerraformStateRegistry |
| `retryAt` | Time | Timestamp after which the TerraformStateRegistry should be resynced |
| `retryCount` | Int | Number of consecutive failed sync attempts of the TerraformStateRegistry |
| `state` | RegistryState | Sync state of the TerraformStateRegistry |
| `terraformStateId` | ID! | ID of the TerraformState |
## TestReport
Represents a requirement test report.
......
......@@ -566,7 +566,7 @@ the Admin Area UI, and Prometheus!
null: true,
resolver: ::Resolvers::Geo::WidgetRegistriesResolver,
description: 'Find widget registries on this Geo node',
feature_flag: :geo_self_service_framework
feature_flag: :geo_widget_replication
```
1. Add the new `widget_registries` field name to the `expected_fields` array in
......
# frozen_string_literal: true
module Geo
class TerraformStateRegistryFinder
include FrameworkRegistryFinder
end
end
# frozen_string_literal: true
module Resolvers
module Geo
class TerraformStateRegistriesResolver < BaseResolver
include RegistriesResolver
end
end
end
......@@ -26,7 +26,12 @@ module Types
null: true,
resolver: ::Resolvers::Geo::PackageFileRegistriesResolver,
description: 'Package file registries of the GeoNode',
feature_flag: :geo_self_service_framework
feature_flag: :geo_package_file_replication
field :terraform_state_registries, ::Types::Geo::TerraformStateRegistryType.connection_type,
null: true,
resolver: ::Resolvers::Geo::TerraformStateRegistriesResolver,
description: 'Find terraform state registries on this Geo node',
feature_flag: :geo_terraform_state_replication
end
end
end
# frozen_string_literal: true
module Types
module Geo
# rubocop:disable Graphql/AuthorizeTypes because it is included
class TerraformStateRegistryType < BaseObject
include ::Types::Geo::RegistryType
graphql_name 'TerraformStateRegistry'
description 'Represents the sync and verification state of a terraform state'
field :terraform_state_id, GraphQL::ID_TYPE, null: false, description: 'ID of the TerraformState'
end
end
end
---
title: Add graphql endpoints for terraform state store
merge_request: 40317
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::TerraformStateRegistryFinder do
it_behaves_like 'a framework registry finder', :geo_terraform_state_registry
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Resolvers::Geo::TerraformStateRegistriesResolver do
it_behaves_like 'a Geo registries resolver', :geo_terraform_state_registry
end
......@@ -12,6 +12,7 @@ RSpec.describe GitlabSchema.types['GeoNode'] do
container_repositories_max_capacity sync_object_storage
selective_sync_type selective_sync_shards selective_sync_namespaces
minimum_reverification_interval package_file_registries
terraform_state_registries
]
expect(described_class).to have_graphql_fields(*expected_fields)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['TerraformStateRegistry'] do
it_behaves_like 'a Geo registry type'
it 'has the expected fields (other than those included in RegistryType)' do
expected_fields = %i[terraform_state_id]
expect(described_class).to have_graphql_fields(*expected_fields).at_least
end
end
......@@ -9,4 +9,11 @@ RSpec.describe 'Gets registries' do
registry_factory: :geo_package_file_registry,
registry_foreign_key_field_name: 'packageFileId'
}
it_behaves_like 'gets registries for', {
field_name: 'terraformStateRegistries',
registry_class_name: 'TerraformStateRegistry',
registry_factory: :geo_terraform_state_registry,
registry_foreign_key_field_name: 'terraformStateId'
}
end
......@@ -5,6 +5,7 @@ RSpec.shared_examples 'gets registries for' do |args|
let(:registry_class_name) { args[:registry_class_name] }
let(:registry_factory) { args[:registry_factory] }
let(:registry_foreign_key_field_name) { args[:registry_foreign_key_field_name] }
let(:feature_flag) { Geo.const_get(registry_class_name, false).replicator_class.replication_enabled_feature_key }
let(:registry_foreign_key) { registry_foreign_key_field_name.underscore }
let(:field_name_sym) { field_name.underscore.to_sym }
......@@ -109,7 +110,7 @@ RSpec.shared_examples 'gets registries for' do |args|
context 'when the geo_self_service_framework feature is disabled' do
before do
stub_feature_flags(geo_self_service_framework: false)
stub_feature_flags(feature_flag => false)
end
it 'errors when requesting registries' do
......
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