Commit 7211e6ab authored by Alex Kalderimis's avatar Alex Kalderimis Committed by Markus Koller

Use GlobalID in error tracking

This changes the type of id from ID to the more meaningful
GlobalIDType[Gitlab::ErrorTracking::DetailedError]

This is a bit of an interim fix, since these IDs (being sentry IDs
really) don't make much sense as global IDs, which are meant to
represent application resources.
parent e2f4a758
...@@ -5,19 +5,20 @@ module Resolvers ...@@ -5,19 +5,20 @@ module Resolvers
class SentryDetailedErrorResolver < BaseResolver class SentryDetailedErrorResolver < BaseResolver
type Types::ErrorTracking::SentryDetailedErrorType, null: true type Types::ErrorTracking::SentryDetailedErrorType, null: true
argument :id, GraphQL::ID_TYPE, argument :id, ::Types::GlobalIDType[::Gitlab::ErrorTracking::DetailedError],
required: true, required: true,
description: 'ID of the Sentry issue' description: 'ID of the Sentry issue'
def resolve(**args) def resolve(id:)
current_user = context[:current_user] # TODO: remove this line when the compatibility layer is removed
issue_id = GlobalID.parse(args[:id])&.model_id # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
id = ::Types::GlobalIDType[::Gitlab::ErrorTracking::DetailedError].coerce_isolated_input(id)
# Get data from Sentry # Get data from Sentry
response = ::ErrorTracking::IssueDetailsService.new( response = ::ErrorTracking::IssueDetailsService.new(
project, project,
current_user, current_user,
{ issue_id: issue_id } { issue_id: id.model_id }
).execute ).execute
issue = response[:issue] issue = response[:issue]
issue.gitlab_project = project if issue issue.gitlab_project = project if issue
......
...@@ -3,18 +3,20 @@ ...@@ -3,18 +3,20 @@
module Resolvers module Resolvers
module ErrorTracking module ErrorTracking
class SentryErrorStackTraceResolver < BaseResolver class SentryErrorStackTraceResolver < BaseResolver
argument :id, GraphQL::ID_TYPE, argument :id, ::Types::GlobalIDType[::Gitlab::ErrorTracking::DetailedError],
required: true, required: true,
description: 'ID of the Sentry issue' description: 'ID of the Sentry issue'
def resolve(**args) def resolve(id:)
issue_id = GlobalID.parse(args[:id])&.model_id # TODO: remove this line when the compatibility layer is removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
id = ::Types::GlobalIDType[::Gitlab::ErrorTracking::DetailedError].coerce_isolated_input(id)
# Get data from Sentry # Get data from Sentry
response = ::ErrorTracking::IssueLatestEventService.new( response = ::ErrorTracking::IssueLatestEventService.new(
project, project,
current_user, current_user,
{ issue_id: issue_id } { issue_id: id.model_id }
).execute ).execute
event = response[:latest_event] event = response[:latest_event]
......
---
title: Use global IDs for GraphQL arguments accepting sentry IDs
merge_request: 36098
author:
type: changed
...@@ -8097,6 +8097,11 @@ type GeoNode { ...@@ -8097,6 +8097,11 @@ type GeoNode {
verificationMaxCapacity: Int verificationMaxCapacity: Int
} }
"""
Identifier of Gitlab::ErrorTracking::DetailedError
"""
scalar GitlabErrorTrackingDetailedErrorID
type GrafanaIntegration { type GrafanaIntegration {
""" """
Timestamp of the issue's creation Timestamp of the issue's creation
...@@ -15910,7 +15915,7 @@ type Project { ...@@ -15910,7 +15915,7 @@ type Project {
""" """
ID of the Sentry issue ID of the Sentry issue
""" """
id: ID! id: GitlabErrorTrackingDetailedErrorID!
): SentryDetailedError ): SentryDetailedError
""" """
...@@ -19249,7 +19254,7 @@ type SentryErrorCollection { ...@@ -19249,7 +19254,7 @@ type SentryErrorCollection {
""" """
ID of the Sentry issue ID of the Sentry issue
""" """
id: ID! id: GitlabErrorTrackingDetailedErrorID!
): SentryDetailedError ): SentryDetailedError
""" """
...@@ -19259,7 +19264,7 @@ type SentryErrorCollection { ...@@ -19259,7 +19264,7 @@ type SentryErrorCollection {
""" """
ID of the Sentry issue ID of the Sentry issue
""" """
id: ID! id: GitlabErrorTrackingDetailedErrorID!
): SentryErrorStackTrace ): SentryErrorStackTrace
""" """
......
...@@ -22356,6 +22356,16 @@ ...@@ -22356,6 +22356,16 @@
"enumValues": null, "enumValues": null,
"possibleTypes": null "possibleTypes": null
}, },
{
"kind": "SCALAR",
"name": "GitlabErrorTrackingDetailedErrorID",
"description": "Identifier of Gitlab::ErrorTracking::DetailedError",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{ {
"kind": "OBJECT", "kind": "OBJECT",
"name": "GrafanaIntegration", "name": "GrafanaIntegration",
...@@ -46148,7 +46158,7 @@ ...@@ -46148,7 +46158,7 @@
"name": null, "name": null,
"ofType": { "ofType": {
"kind": "SCALAR", "kind": "SCALAR",
"name": "ID", "name": "GitlabErrorTrackingDetailedErrorID",
"ofType": null "ofType": null
} }
}, },
...@@ -55651,7 +55661,7 @@ ...@@ -55651,7 +55661,7 @@
"name": null, "name": null,
"ofType": { "ofType": {
"kind": "SCALAR", "kind": "SCALAR",
"name": "ID", "name": "GitlabErrorTrackingDetailedErrorID",
"ofType": null "ofType": null
} }
}, },
...@@ -55678,7 +55688,7 @@ ...@@ -55678,7 +55688,7 @@
"name": null, "name": null,
"ofType": { "ofType": {
"kind": "SCALAR", "kind": "SCALAR",
"name": "ID", "name": "GitlabErrorTrackingDetailedErrorID",
"ofType": null "ofType": null
} }
}, },
...@@ -65,7 +65,9 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do ...@@ -65,7 +65,9 @@ RSpec.describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do
context 'blank id' do context 'blank id' do
let(:args) { { id: '' } } let(:args) { { id: '' } }
it_behaves_like 'it resolves to nil' it 'responds with an error' do
expect { resolve_error(args) }.to raise_error(::GraphQL::CoercionError)
end
end end
end end
......
...@@ -191,7 +191,7 @@ RSpec.describe 'sentry errors requests' do ...@@ -191,7 +191,7 @@ RSpec.describe 'sentry errors requests' do
describe 'getting a stack trace' do describe 'getting a stack trace' do
let_it_be(:sentry_stack_trace) { build(:error_tracking_error_event) } let_it_be(:sentry_stack_trace) { build(:error_tracking_error_event) }
let(:sentry_gid) { Gitlab::ErrorTracking::DetailedError.new(id: 1).to_global_id.to_s } let(:sentry_gid) { global_id_of(Gitlab::ErrorTracking::DetailedError.new(id: 1)) }
let(:stack_trace_fields) do let(:stack_trace_fields) do
all_graphql_fields_for('SentryErrorStackTrace'.classify) all_graphql_fields_for('SentryErrorStackTrace'.classify)
......
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