summaryrefslogtreecommitdiff
path: root/app/graphql/types/alert_management
diff options
context:
space:
mode:
Diffstat (limited to 'app/graphql/types/alert_management')
-rw-r--r--app/graphql/types/alert_management/http_integration_type.rb22
-rw-r--r--app/graphql/types/alert_management/integration_type.rb58
-rw-r--r--app/graphql/types/alert_management/integration_type_enum.rb13
-rw-r--r--app/graphql/types/alert_management/prometheus_integration_type.rb38
4 files changed, 131 insertions, 0 deletions
diff --git a/app/graphql/types/alert_management/http_integration_type.rb b/app/graphql/types/alert_management/http_integration_type.rb
new file mode 100644
index 00000000000..88782050b94
--- /dev/null
+++ b/app/graphql/types/alert_management/http_integration_type.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module Types
+ module AlertManagement
+ class HttpIntegrationType < BaseObject
+ graphql_name 'AlertManagementHttpIntegration'
+ description 'An endpoint and credentials used to accept alerts for a project'
+
+ implements(Types::AlertManagement::IntegrationType)
+
+ authorize :admin_operations
+
+ def type
+ :http
+ end
+
+ def api_url
+ nil
+ end
+ end
+ end
+end
diff --git a/app/graphql/types/alert_management/integration_type.rb b/app/graphql/types/alert_management/integration_type.rb
new file mode 100644
index 00000000000..bf599885584
--- /dev/null
+++ b/app/graphql/types/alert_management/integration_type.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+module Types
+ module AlertManagement
+ module IntegrationType
+ include Types::BaseInterface
+ graphql_name 'AlertManagementIntegration'
+
+ field :id,
+ GraphQL::ID_TYPE,
+ null: false,
+ description: 'ID of the integration'
+
+ field :type,
+ AlertManagement::IntegrationTypeEnum,
+ null: false,
+ description: 'Type of integration'
+
+ field :name,
+ GraphQL::STRING_TYPE,
+ null: true,
+ description: 'Name of the integration'
+
+ field :active,
+ GraphQL::BOOLEAN_TYPE,
+ null: true,
+ description: 'Whether the endpoint is currently accepting alerts'
+
+ field :token,
+ GraphQL::STRING_TYPE,
+ null: true,
+ description: 'Token used to authenticate alert notification requests'
+
+ field :url,
+ GraphQL::STRING_TYPE,
+ null: true,
+ description: 'Endpoint which accepts alert notifications'
+
+ field :api_url,
+ GraphQL::STRING_TYPE,
+ null: true,
+ description: 'URL at which Prometheus metrics can be queried to populate the metrics dashboard'
+
+ definition_methods do
+ def resolve_type(object, context)
+ if object.is_a?(::PrometheusService)
+ Types::AlertManagement::PrometheusIntegrationType
+ else
+ Types::AlertManagement::HttpIntegrationType
+ end
+ end
+ end
+
+ orphan_types Types::AlertManagement::PrometheusIntegrationType,
+ Types::AlertManagement::HttpIntegrationType
+ end
+ end
+end
diff --git a/app/graphql/types/alert_management/integration_type_enum.rb b/app/graphql/types/alert_management/integration_type_enum.rb
new file mode 100644
index 00000000000..2f9be549e58
--- /dev/null
+++ b/app/graphql/types/alert_management/integration_type_enum.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module Types
+ module AlertManagement
+ class IntegrationTypeEnum < BaseEnum
+ graphql_name 'AlertManagementIntegrationType'
+ description 'Values of types of integrations'
+
+ value 'PROMETHEUS', 'Prometheus integration', value: :prometheus
+ value 'HTTP', 'Integration with any monitoring tool', value: :http
+ end
+ end
+end
diff --git a/app/graphql/types/alert_management/prometheus_integration_type.rb b/app/graphql/types/alert_management/prometheus_integration_type.rb
new file mode 100644
index 00000000000..f605e325b8b
--- /dev/null
+++ b/app/graphql/types/alert_management/prometheus_integration_type.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+module Types
+ module AlertManagement
+ class PrometheusIntegrationType < BaseObject
+ include ::Gitlab::Routing
+
+ graphql_name 'AlertManagementPrometheusIntegration'
+ description 'An endpoint and credentials used to accept Prometheus alerts for a project'
+
+ implements(Types::AlertManagement::IntegrationType)
+
+ authorize :admin_project
+
+ alias_method :prometheus_service, :object
+
+ def name
+ prometheus_service.title
+ end
+
+ def type
+ :prometheus
+ end
+
+ def token
+ prometheus_service.project&.alerting_setting&.token
+ end
+
+ def url
+ prometheus_service.project && notify_project_prometheus_alerts_url(prometheus_service.project, format: :json)
+ end
+
+ def active
+ prometheus_service.manual_configuration?
+ end
+ end
+ end
+end