Commit 140f2a93 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Make NetworkAlertService a user-less service

parent cc0bc406
...@@ -2,12 +2,17 @@ ...@@ -2,12 +2,17 @@
module AlertManagement module AlertManagement
# Create alerts coming K8 through gitlab-agent # Create alerts coming K8 through gitlab-agent
class NetworkAlertService < BaseService class NetworkAlertService
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
include ::IncidentManagement::Settings include ::IncidentManagement::Settings
MONITORING_TOOL = Gitlab::AlertManagement::Payload::MONITORING_TOOLS.fetch(:cilium) MONITORING_TOOL = Gitlab::AlertManagement::Payload::MONITORING_TOOLS.fetch(:cilium)
def initialize(project, payload)
@project = project
@payload = payload
end
# Users of this service need to check the agent token before calling `execute`. # Users of this service need to check the agent token before calling `execute`.
# https://gitlab.com/gitlab-org/gitlab/-/issues/292707 will handle token within the service. # https://gitlab.com/gitlab-org/gitlab/-/issues/292707 will handle token within the service.
def execute def execute
...@@ -24,8 +29,10 @@ module AlertManagement ...@@ -24,8 +29,10 @@ module AlertManagement
private private
attr_reader :project, :payload
def valid_payload_size? def valid_payload_size?
Gitlab::Utils::DeepSize.new(params).valid? Gitlab::Utils::DeepSize.new(payload).valid?
end end
def process_request def process_request
...@@ -78,7 +85,7 @@ module AlertManagement ...@@ -78,7 +85,7 @@ module AlertManagement
strong_memoize(:incoming_payload) do strong_memoize(:incoming_payload) do
Gitlab::AlertManagement::Payload.parse( Gitlab::AlertManagement::Payload.parse(
project, project,
params, payload,
monitoring_tool: MONITORING_TOOL monitoring_tool: MONITORING_TOOL
) )
end end
......
...@@ -25,7 +25,7 @@ module EE ...@@ -25,7 +25,7 @@ module EE
forbidden! unless project.feature_available?(:cilium_alerts) forbidden! unless project.feature_available?(:cilium_alerts)
result = ::AlertManagement::NetworkAlertService.new(agent.project, nil, params[:alert]).execute result = ::AlertManagement::NetworkAlertService.new(agent.project, params[:alert]).execute
status result.http_status status result.http_status
end end
......
...@@ -7,7 +7,7 @@ RSpec.describe AlertManagement::NetworkAlertService do ...@@ -7,7 +7,7 @@ RSpec.describe AlertManagement::NetworkAlertService do
let_it_be(:environment) { create(:environment, project: project) } let_it_be(:environment) { create(:environment, project: project) }
describe '#execute' do describe '#execute' do
let(:service) { described_class.new(project, nil, payload) } let(:service) { described_class.new(project, payload) }
let(:tool) { Gitlab::AlertManagement::Payload::MONITORING_TOOLS[:cilium] } let(:tool) { Gitlab::AlertManagement::Payload::MONITORING_TOOLS[:cilium] }
let(:starts_at) { Time.current.change(usec: 0) } let(:starts_at) { Time.current.change(usec: 0) }
let(:ended_at) { nil } let(:ended_at) { nil }
......
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