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

Make NetworkAlertService a user-less service

parent cc0bc406
......@@ -2,12 +2,17 @@
module AlertManagement
# Create alerts coming K8 through gitlab-agent
class NetworkAlertService < BaseService
class NetworkAlertService
include Gitlab::Utils::StrongMemoize
include ::IncidentManagement::Settings
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`.
# https://gitlab.com/gitlab-org/gitlab/-/issues/292707 will handle token within the service.
def execute
......@@ -24,8 +29,10 @@ module AlertManagement
private
attr_reader :project, :payload
def valid_payload_size?
Gitlab::Utils::DeepSize.new(params).valid?
Gitlab::Utils::DeepSize.new(payload).valid?
end
def process_request
......@@ -78,7 +85,7 @@ module AlertManagement
strong_memoize(:incoming_payload) do
Gitlab::AlertManagement::Payload.parse(
project,
params,
payload,
monitoring_tool: MONITORING_TOOL
)
end
......
......@@ -25,7 +25,7 @@ module EE
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
end
......
......@@ -7,7 +7,7 @@ RSpec.describe AlertManagement::NetworkAlertService do
let_it_be(:environment) { create(:environment, project: project) }
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(:starts_at) { Time.current.change(usec: 0) }
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