Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2344fddb
Commit
2344fddb
authored
Jan 28, 2022
by
harsimarsandhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch GitLab::HTTP:ERRORS while streaming auditevents
Changelog: fixed EE: true
parent
1b2fd94b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
0 deletions
+52
-0
ee/app/workers/audit_events/audit_event_streaming_worker.rb
ee/app/workers/audit_events/audit_event_streaming_worker.rb
+3
-0
ee/spec/workers/audit_events/audit_event_streaming_worker_spec.rb
...workers/audit_events/audit_event_streaming_worker_spec.rb
+49
-0
No files found.
ee/app/workers/audit_events/audit_event_streaming_worker.rb
View file @
2344fddb
...
@@ -29,6 +29,9 @@ module AuditEvents
...
@@ -29,6 +29,9 @@ module AuditEvents
body:
Gitlab
::
Json
::
LimitedEncoder
.
encode
(
audit_event
.
as_json
,
limit:
REQUEST_BODY_SIZE_LIMIT
),
body:
Gitlab
::
Json
::
LimitedEncoder
.
encode
(
audit_event
.
as_json
,
limit:
REQUEST_BODY_SIZE_LIMIT
),
use_read_total_timeout:
true
,
use_read_total_timeout:
true
,
headers:
{
HEADER_KEY
=>
destination
.
verification_token
})
headers:
{
HEADER_KEY
=>
destination
.
verification_token
})
rescue
URI
::
InvalidURIError
=>
e
Gitlab
::
ErrorTracking
.
log_exception
(
e
)
rescue
*
Gitlab
::
HTTP
::
HTTP_ERRORS
end
end
end
end
...
...
ee/spec/workers/audit_events/audit_event_streaming_worker_spec.rb
View file @
2344fddb
...
@@ -65,6 +65,43 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do
...
@@ -65,6 +65,43 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do
end
end
end
end
shared_examples
'a http post error is raised'
do
subject
{
worker
.
perform
(
event
.
id
)
}
context
'when any of Gitlab::HTTP::HTTP_ERRORS is raised'
do
Gitlab
::
HTTP
::
HTTP_ERRORS
.
each
do
|
error_klass
|
let
(
:error
)
{
error_klass
.
new
(
'error'
)
}
before
do
allow
(
Gitlab
::
HTTP
).
to
receive
(
:post
).
and_raise
(
error
)
end
it
'does not logs the error'
do
expect
(
Gitlab
::
ErrorTracking
).
not_to
receive
(
:log_exception
).
with
(
an_instance_of
(
error_klass
)
)
subject
end
end
end
context
'when URI::InvalidURIError exception is raised'
do
let
(
:error
)
{
URI
::
InvalidURIError
.
new
(
'invalid uri'
)
}
before
do
group
.
external_audit_event_destinations
.
create!
(
destination_url:
'http://example.com'
)
allow
(
Gitlab
::
HTTP
).
to
receive
(
:post
).
and_raise
(
error
)
end
it
'logs the error'
do
expect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:log_exception
).
with
(
an_instance_of
(
URI
::
InvalidURIError
)
).
once
subject
end
end
end
describe
"#perform"
do
describe
"#perform"
do
context
'when the entity type is a group'
do
context
'when the entity type is a group'
do
it_behaves_like
'a successful audit event stream'
do
it_behaves_like
'a successful audit event stream'
do
...
@@ -72,6 +109,12 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do
...
@@ -72,6 +109,12 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do
let
(
:group
)
{
event
.
entity
}
let
(
:group
)
{
event
.
entity
}
end
end
it_behaves_like
'a http post error is raised'
do
let_it_be
(
:event
)
{
create
(
:audit_event
,
:group_event
)
}
let
(
:group
)
{
event
.
entity
}
end
end
end
context
'when the entity type is a project that belongs to a group'
do
context
'when the entity type is a project that belongs to a group'
do
...
@@ -80,6 +123,12 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do
...
@@ -80,6 +123,12 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do
let_it_be
(
:project
)
{
create
(
:project
,
group:
group
)
}
let_it_be
(
:project
)
{
create
(
:project
,
group:
group
)
}
let_it_be
(
:event
)
{
create
(
:audit_event
,
:project_event
,
target_project:
project
)
}
let_it_be
(
:event
)
{
create
(
:audit_event
,
:project_event
,
target_project:
project
)
}
end
end
it_behaves_like
'a http post error is raised'
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:project
)
{
create
(
:project
,
group:
group
)
}
let_it_be
(
:event
)
{
create
(
:audit_event
,
:project_event
,
target_project:
project
)
}
end
end
end
context
'when the entity type is a project at a root namespace level'
do
context
'when the entity type is a project at a root namespace level'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment