Skip to content
代码片段 群组 项目
未验证 提交 1cb92b39 编辑于 作者: Ankit Bhatnagar's avatar Ankit Bhatnagar
浏览文件

Persist traces issues connections when creating O11y linked issues

EE: true
上级 f80ed731
No related branches found
No related tags found
无相关合并请求
......@@ -23,6 +23,14 @@ def gather_observability_values(params)
traceId: parsed['traceId']
}
}
elsif params[:observability_trace_details].present?
parsed = ::Gitlab::Json.parse(CGI.unescape(params[:observability_trace_details]))
{
trace: {
traceId: parsed['traceId']
}
}
end
end
......
......@@ -5,6 +5,7 @@ module IssueLinks
class CreateService < BaseService
METRICS_ATTRS = [:metric_details_name, :metric_details_type].freeze
LOGS_ATTRS = [:log_service_name, :log_severity_number, :log_timestamp, :log_fingerprint, :log_trace_id].freeze
TRACES_ATTRS = [:trace_id].freeze
def execute
return ServiceResponse.error(message: 'No permission') unless allowed?
......@@ -17,6 +18,8 @@ def execute
persist_metrics_links(issue, links)
elsif all_keys_present?(links, LOGS_ATTRS)
persist_logs_links(issue, links)
elsif all_keys_present?(links, TRACES_ATTRS)
persist_traces_links(issue, links)
else
ServiceResponse.error(message: 'Insufficient link params')
end
......@@ -62,6 +65,19 @@ def persist_logs_links(issue, links)
ServiceResponse.success
end
def persist_traces_links(issue, links)
begin
::Observability::TracesIssuesConnection.create!(
trace_identifier: links[:trace_id],
issue: issue
)
rescue ActiveRecord::RecordInvalid => e
return ServiceResponse.error(message: e.message)
end
ServiceResponse.success
end
end
end
end
......@@ -10,3 +10,5 @@
= hidden_field_tag 'observability_links[log_trace_id]', observability_values.dig(:log, :traceId)
= hidden_field_tag 'observability_links[log_timestamp]', observability_values.dig(:log, :timestamp)
= hidden_field_tag 'observability_links[log_fingerprint]', observability_values.dig(:log, :fingerprint)
= hidden_field_tag 'observability_links[trace_id]', observability_values.dig(:trace, :traceId)
......@@ -510,6 +510,12 @@ def send_request
end
context 'when observability_tracing_details parameters exist' do
it 'does not populate observability_values' do
subject
expect(assigns(:observability_values)).to be_nil
end
it 'does not prefill the issue title and description' do
subject
......@@ -521,6 +527,12 @@ def send_request
context 'when observability_tracing_details parameters do not exist' do
let(:tracing_params) { {} }
it 'does not populate observability_values' do
subject
expect(assigns(:observability_values)).to be_nil
end
it 'does not prefill the issue title and description' do
subject
......@@ -539,6 +551,11 @@ def send_request
it 'does prefill the issue title and description' do
subject
expect(assigns(:observability_values)).to eq({
trace: {
traceId: '8335ed4c-c943-aeaa-7851-2b9af6c5d3b8'
}
})
expect(assigns(:issue).title).to eq("Issue created from trace 'frontend-proxy : ingress'")
expect(assigns(:issue).description).to eq(
<<~TEXT
......@@ -557,6 +574,12 @@ def send_request
context 'when observability_tracing_details parameters do not exist' do
let(:tracing_params) { {} }
it 'does not populate observability_values' do
subject
expect(assigns(:observability_values)).to be_nil
end
it 'does not prefill the issue title and description' do
subject
......
......@@ -413,6 +413,56 @@
end
end
context 'when handling issues linked to observability traces' do
before do
project.add_developer(user)
end
let(:additional_params) do
{
observability_links: {
trace_id: "fa12d360-54cd-c4db-5241-ccf7841d3e72"
}
}
end
let(:execute) { service.execute }
let(:returned_issue) { execute[:issue] }
context 'when observability is enabled and licensed' do
before do
stub_licensed_features(observability: true)
end
it "creates a traces connection" do
expect { execute }.to change { ::Observability::TracesIssuesConnection.count }.by(1)
end
context 'when no o11y params exist' do
let(:additional_params) { {} }
it "creates no traces connection" do
expect { execute }.not_to change { ::Observability::TracesIssuesConnection.count }
end
it "creates an issue" do
expect { execute }.to change { ::Issue.count }.by(1)
end
end
end
context 'when observability is not enabled and licensed' do
before do
stub_feature_flags(observability_features: false)
stub_licensed_features(observability: false)
end
it "creates no traces connection" do
expect { execute }.not_to change { ::Observability::TracesIssuesConnection.count }
end
end
end
it_behaves_like 'new issuable with scoped labels' do
let(:parent) { project }
let(:service_result) { described_class.new(**args).execute }
......
......@@ -3,16 +3,19 @@
require 'spec_helper'
RSpec.describe Observability::IssueLinks::CreateService, feature_category: :metrics do
let(:issue) { create(:issue) }
let(:project) { issue.project }
let(:user) { create(:user) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:issue) { create(:issue, project: project) }
let(:links) { {} }
let(:service) { described_class.new(project, user, issue: issue, links: links) }
let(:execute) { service.execute }
describe '#execute' do
before do
before_all do
project.add_developer(user)
end
before do
stub_licensed_features(observability: true)
end
......@@ -59,6 +62,18 @@
expect { execute }.to change { ::Observability::MetricsIssuesConnection.count }.by(1)
expect(execute.status).to eq(:success)
end
context 'when invalid link-params are passed' do
before do
links[:metric_details_name] = "*" * 501 # can be 500 characters long only
end
it 'creates no metric connection' do
expect { execute }.not_to change { ::Observability::MetricsIssuesConnection.count }
expect(execute.status).to eq(:error)
expect(execute.message).to include("Validation failed")
end
end
end
context 'when persisting observability logs links' do
......@@ -79,11 +94,37 @@
context 'when invalid link-params are passed' do
before do
links[:log_severity_number] = 100
links[:log_severity_number] = 100 # can be 1 .. 24 only
end
it 'creates no log connection' do
expect { execute }.not_to change { ::Observability::LogsIssuesConnection.count }
expect(execute.status).to eq(:error)
expect(execute.message).to include("Validation failed")
end
end
end
context 'when persisting observability trace links' do
let(:links) do
{
trace_id: "fa12d360-54cd-c4db-5241-ccf7841d3e72"
}
end
it 'creates a trace connection' do
expect { execute }.to change { ::Observability::TracesIssuesConnection.count }.by(1)
expect(execute.status).to eq(:success)
end
context 'when invalid link-params are passed' do
before do
links[:trace_id] = "*" * 129 # can be 128 characters only
end
it 'creates no trace connection' do
expect { execute }.not_to change { ::Observability::TracesIssuesConnection.count }
expect(execute.status).to eq(:error)
expect(execute.message).to include("Validation failed")
end
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册