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
f2182208
Commit
f2182208
authored
Mar 03, 2021
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab master
parents
a4bd5f29
08187218
Changes
28
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
676 additions
and
304 deletions
+676
-304
app/assets/javascripts/environments/mixins/environments_pagination_api_mixin.js
.../environments/mixins/environments_pagination_api_mixin.js
+2
-0
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+6
-6
app/controllers/graphql_controller.rb
app/controllers/graphql_controller.rb
+13
-1
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+1
-1
changelogs/unreleased/qmnguyen0711-846-sentry-merge-sentry-s-contexts-and-users-into-applicatio.yml
...try-merge-sentry-s-contexts-and-users-into-applicatio.yml
+5
-0
changelogs/unreleased/show-nested-env.yml
changelogs/unreleased/show-nested-env.yml
+5
-0
doc/administration/pages/index.md
doc/administration/pages/index.md
+7
-6
doc/administration/pseudonymizer.md
doc/administration/pseudonymizer.md
+2
-2
doc/administration/terraform_state.md
doc/administration/terraform_state.md
+1
-1
doc/administration/uploads.md
doc/administration/uploads.md
+1
-1
ee/lib/gitlab/database/load_balancing/service_discovery.rb
ee/lib/gitlab/database/load_balancing/service_discovery.rb
+1
-1
ee/spec/lib/gitlab/database/load_balancing/service_discovery_spec.rb
.../gitlab/database/load_balancing/service_discovery_spec.rb
+2
-2
lib/api/helpers.rb
lib/api/helpers.rb
+1
-1
lib/gitlab/application_context.rb
lib/gitlab/application_context.rb
+5
-1
lib/gitlab/error_tracking.rb
lib/gitlab/error_tracking.rb
+5
-55
lib/gitlab/error_tracking/context_payload_generator.rb
lib/gitlab/error_tracking/context_payload_generator.rb
+66
-0
lib/gitlab/error_tracking/log_formatter.rb
lib/gitlab/error_tracking/log_formatter.rb
+55
-0
lib/gitlab/error_tracking/processor/context_payload_processor.rb
...lab/error_tracking/processor/context_payload_processor.rb
+18
-0
lib/gitlab/exception_log_formatter.rb
lib/gitlab/exception_log_formatter.rb
+0
-10
spec/frontend/environments/environments_app_spec.js
spec/frontend/environments/environments_app_spec.js
+10
-2
spec/frontend/environments/folder/environments_folder_view_spec.js
...tend/environments/folder/environments_folder_view_spec.js
+12
-2
spec/lib/gitlab/error_tracking/context_payload_generator_spec.rb
...b/gitlab/error_tracking/context_payload_generator_spec.rb
+176
-0
spec/lib/gitlab/error_tracking/log_formatter_spec.rb
spec/lib/gitlab/error_tracking/log_formatter_spec.rb
+71
-0
spec/lib/gitlab/error_tracking/processor/context_payload_processor_spec.rb
...rror_tracking/processor/context_payload_processor_spec.rb
+45
-0
spec/lib/gitlab/error_tracking_spec.rb
spec/lib/gitlab/error_tracking_spec.rb
+85
-134
spec/models/upload_spec.rb
spec/models/upload_spec.rb
+1
-1
spec/requests/api/graphql/project/merge_requests_spec.rb
spec/requests/api/graphql/project/merge_requests_spec.rb
+78
-59
spec/requests/api/helpers_spec.rb
spec/requests/api/helpers_spec.rb
+2
-18
No files found.
app/assets/javascripts/environments/mixins/environments_pagination_api_mixin.js
View file @
f2182208
...
...
@@ -16,6 +16,7 @@ export default {
let
params
=
{
scope
,
page
:
'
1
'
,
nested
:
true
,
};
params
=
this
.
onChangeWithFilter
(
params
);
...
...
@@ -27,6 +28,7 @@ export default {
/* URLS parameters are strings, we need to parse to match types */
let
params
=
{
page
:
Number
(
page
).
toString
(),
nested
:
true
,
};
if
(
this
.
scope
)
{
...
...
app/controllers/application_controller.rb
View file @
f2182208
...
...
@@ -29,7 +29,6 @@ class ApplicationController < ActionController::Base
before_action
:validate_user_service_ticket!
before_action
:check_password_expiration
,
if: :html_request?
before_action
:ldap_security_check
around_action
:sentry_context
before_action
:default_headers
before_action
:default_cache_headers
before_action
:add_gon_variables
,
if: :html_request?
...
...
@@ -171,7 +170,12 @@ class ApplicationController < ActionController::Base
end
def
log_exception
(
exception
)
Gitlab
::
ErrorTracking
.
track_exception
(
exception
)
# At this point, the controller already exits set_current_context around
# block. To maintain the context while handling error exception, we need to
# set the context again
set_current_context
do
Gitlab
::
ErrorTracking
.
track_exception
(
exception
)
end
backtrace_cleaner
=
request
.
env
[
"action_dispatch.backtrace_cleaner"
]
application_trace
=
ActionDispatch
::
ExceptionWrapper
.
new
(
backtrace_cleaner
,
exception
).
application_trace
...
...
@@ -528,10 +532,6 @@ class ApplicationController < ActionController::Base
.
execute
end
def
sentry_context
(
&
block
)
Gitlab
::
ErrorTracking
.
with_context
(
current_user
,
&
block
)
end
def
allow_gitaly_ref_name_caching
::
Gitlab
::
GitalyClient
.
allow_ref_name_caching
do
yield
...
...
app/controllers/graphql_controller.rb
View file @
f2182208
...
...
@@ -4,6 +4,8 @@ class GraphqlController < ApplicationController
# Unauthenticated users have access to the API for public data
skip_before_action
:authenticate_user!
WHITELIST_HEADER
=
'HTTP_X_GITLAB_QUERY_WHITELIST_ISSUE'
# If a user is using their session to access GraphQL, we need to have session
# storage, since the admin-mode check is session wide.
# We can't enable this for anonymous users because that would cause users using
...
...
@@ -21,6 +23,7 @@ class GraphqlController < ApplicationController
before_action
(
only:
[
:execute
])
{
authenticate_sessionless_user!
(
:api
)
}
before_action
:set_user_last_activity
before_action
:track_vs_code_usage
before_action
:whitelist_query!
# Since we deactivate authentication from the main ApplicationController and
# defer it to :authorize_access_api!, we need to override the bypass session
...
...
@@ -59,6 +62,14 @@ class GraphqlController < ApplicationController
private
# Tests may mark some queries as exempt from query limits
def
whitelist_query!
whitelist_issue
=
request
.
headers
[
WHITELIST_HEADER
]
return
unless
whitelist_issue
Gitlab
::
QueryLimiting
.
whitelist
(
whitelist_issue
)
end
def
set_user_last_activity
return
unless
current_user
...
...
@@ -66,7 +77,8 @@ class GraphqlController < ApplicationController
end
def
track_vs_code_usage
Gitlab
::
UsageDataCounters
::
VSCodeExtensionActivityUniqueCounter
.
track_api_request_when_trackable
(
user_agent:
request
.
user_agent
,
user:
current_user
)
Gitlab
::
UsageDataCounters
::
VSCodeExtensionActivityUniqueCounter
.
track_api_request_when_trackable
(
user_agent:
request
.
user_agent
,
user:
current_user
)
end
def
execute_multiplex
...
...
app/services/merge_requests/base_service.rb
View file @
f2182208
...
...
@@ -181,7 +181,7 @@ module MergeRequests
}
if
exception
Gitlab
::
ErrorTracking
.
with_context
(
current_user
)
do
Gitlab
::
ApplicationContext
.
with_context
(
user:
current_user
)
do
Gitlab
::
ErrorTracking
.
track_exception
(
exception
,
data
)
end
...
...
changelogs/unreleased/qmnguyen0711-846-sentry-merge-sentry-s-contexts-and-users-into-applicatio.yml
0 → 100644
View file @
f2182208
---
title
:
Merge Sentry's contexts into Gitlab::ApplicationContext
merge_request
:
53691
author
:
type
:
changed
changelogs/unreleased/show-nested-env.yml
0 → 100644
View file @
f2182208
---
title
:
Show nested environments when change tab, page
merge_request
:
55167
author
:
type
:
changed
doc/administration/pages/index.md
View file @
f2182208
...
...
@@ -862,7 +862,7 @@ In installations from source:
remote_directory
:
"
pages"
# The bucket name
connection
:
provider
:
AWS
# Only AWS supported at the moment
aws_access_key_id
:
AWS_ACESS_KEY_ID
aws_access_key_id
:
AWS_AC
C
ESS_KEY_ID
aws_secret_access_key
:
AWS_SECRET_ACCESS_KEY
region
:
eu-central-1
```
...
...
@@ -969,14 +969,15 @@ to define the explicit address that the GitLab Pages daemon should listen on:
gitlab_pages
[
'listen_proxy'
]
=
'127.0.0.1:8090'
```
### 404 error after transferring
project to a different group or user
### 404 error after transferring
the project to a different group or user, or changing project path
If you encounter a
`404 Not Found`
error a Pages site after transferring a project to
another group or user,
you must trigger a domain configuration update for Pages. To do
so, write something in the
`.update`
file. The Pages daemon monitors for changes to this
file, and reloads the configuration when changes occur.
another group or user,
or changing project path, you must trigger a domain configuration
update for Pages. To do so, write something in the
`.update`
file. The Pages daemon
monitors for changes to this
file, and reloads the configuration when changes occur.
Use this example to fix a
`404 Not Found`
error after transferring a project with Pages:
Use this example to fix a
`404 Not Found`
error after transferring a project or changing
a project path with Pages:
```
shell
date
>
/var/opt/gitlab/gitlab-rails/shared/pages/.update
...
...
doc/administration/pseudonymizer.md
View file @
f2182208
...
...
@@ -24,7 +24,7 @@ be textually exported. This ensures that:
## Configuration
To configure the
p
seudonymizer, you need to:
To configure the
P
seudonymizer, you need to:
-
Provide a manifest file that describes which fields should be included or
pseudonymized (
[
example `manifest.yml` file
](
https://gitlab.com/gitlab-org/gitlab/tree/master/config/pseudonymizer.yml
)
).
...
...
@@ -87,7 +87,7 @@ To configure the pseudonymizer, you need to:
## Usage
You can optionally run the
p
seudonymizer using the following environment variables:
You can optionally run the
P
seudonymizer using the following environment variables:
-
`PSEUDONYMIZER_OUTPUT_DIR`
- where to store the output CSV files (defaults to
`/tmp`
)
-
`PSEUDONYMIZER_BATCH`
- the batch size when querying the DB (defaults to
`100000`
)
...
...
doc/administration/terraform_state.md
View file @
f2182208
...
...
@@ -121,7 +121,7 @@ See [the available connection settings for different providers](object_storage.m
remote_directory
:
"
terraform"
# The bucket name
connection
:
provider
:
AWS
# Only AWS supported at the moment
aws_access_key_id
:
AWS_ACESS_KEY_ID
aws_access_key_id
:
AWS_AC
C
ESS_KEY_ID
aws_secret_access_key
:
AWS_SECRET_ACCESS_KEY
region
:
eu-central-1
```
...
...
doc/administration/uploads.md
View file @
f2182208
...
...
@@ -146,7 +146,7 @@ _The uploads are stored by default in
remote_directory
:
"
uploads"
# The bucket name
connection
:
provider
:
AWS
# Only AWS supported at the moment
aws_access_key_id
:
AWS_ACESS_KEY_ID
aws_access_key_id
:
AWS_AC
C
ESS_KEY_ID
aws_secret_access_key
:
AWS_SECRET_ACCESS_KEY
region
:
eu-central-1
```
...
...
ee/lib/gitlab/database/load_balancing/service_discovery.rb
View file @
f2182208
...
...
@@ -59,7 +59,7 @@ module Gitlab
rescue
=>
error
# Any exceptions that might occur should be reported to
# Sentry, instead of silently terminating this thread.
Raven
.
capture
_exception
(
error
)
Gitlab
::
ErrorTracking
.
track
_exception
(
error
)
Gitlab
::
AppLogger
.
error
(
"Service discovery encountered an error:
#{
error
.
message
}
"
...
...
ee/spec/lib/gitlab/database/load_balancing/service_discovery_spec.rb
View file @
f2182208
...
...
@@ -66,8 +66,8 @@ RSpec.describe Gitlab::Database::LoadBalancing::ServiceDiscovery do
.
to
receive
(
:refresh_if_necessary
)
.
and_raise
(
error
)
expect
(
Raven
)
.
to
receive
(
:
capture
_exception
)
expect
(
Gitlab
::
ErrorTracking
)
.
to
receive
(
:
track
_exception
)
.
with
(
error
)
expect
(
service
)
...
...
lib/api/helpers.rb
View file @
f2182208
...
...
@@ -467,7 +467,7 @@ module API
def
handle_api_exception
(
exception
)
if
report_exception?
(
exception
)
define_params_for_grape_middleware
Gitlab
::
ErrorTracking
.
with_context
(
current_user
)
do
Gitlab
::
ApplicationContext
.
with_context
(
user:
current_user
)
do
Gitlab
::
ErrorTracking
.
track_exception
(
exception
)
end
end
...
...
lib/gitlab/application_context.rb
View file @
f2182208
...
...
@@ -27,8 +27,12 @@ module Gitlab
Labkit
::
Context
.
push
(
application_context
.
to_lazy_hash
)
end
def
self
.
current
Labkit
::
Context
.
current
.
to_h
end
def
self
.
current_context_include?
(
attribute_name
)
Labkit
::
Context
.
current
.
to_h
.
include?
(
Labkit
::
Context
.
log_key
(
attribute_name
))
current
.
include?
(
Labkit
::
Context
.
log_key
(
attribute_name
))
end
def
initialize
(
**
args
)
...
...
lib/gitlab/error_tracking.rb
View file @
f2182208
...
...
@@ -27,33 +27,16 @@ module Gitlab
config
.
sanitize_fields
=
Rails
.
application
.
config
.
filter_parameters
.
map
(
&
:to_s
)
config
.
processors
<<
::
Gitlab
::
ErrorTracking
::
Processor
::
SidekiqProcessor
config
.
processors
<<
::
Gitlab
::
ErrorTracking
::
Processor
::
GrpcErrorProcessor
config
.
processors
<<
::
Gitlab
::
ErrorTracking
::
Processor
::
ContextPayloadProcessor
# Sanitize authentication headers
config
.
sanitize_http_headers
=
%w[Authorization Private-Token]
config
.
tags
=
extra_tags_from_env
.
merge
(
program:
Gitlab
.
process_name
)
config
.
before_send
=
method
(
:before_send
)
yield
config
if
block_given?
end
end
def
with_context
(
current_user
=
nil
)
last_user_context
=
Raven
.
context
.
user
user_context
=
{
id:
current_user
&
.
id
,
email:
current_user
&
.
email
,
username:
current_user
&
.
username
}.
compact
Raven
.
tags_context
(
default_tags
)
Raven
.
user_context
(
user_context
)
yield
ensure
Raven
.
user_context
(
last_user_context
)
end
# This should be used when you want to passthrough exception handling:
# rescue and raise to be catched in upper layers of the application.
#
...
...
@@ -118,37 +101,20 @@ module Gitlab
end
def
process_exception
(
exception
,
sentry:
false
,
logging:
true
,
extra
:)
exception
.
try
(
:sentry_extra_data
)
&
.
tap
do
|
data
|
extra
=
extra
.
merge
(
data
)
if
data
.
is_a?
(
Hash
)
end
extra
=
sanitize_request_parameters
(
extra
)
context_payload
=
Gitlab
::
ErrorTracking
::
ContextPayloadGenerator
.
generate
(
exception
,
extra
)
if
sentry
&&
Raven
.
configuration
.
server
Raven
.
capture_exception
(
exception
,
tags:
default_tags
,
extra:
extra
)
Raven
.
capture_exception
(
exception
,
**
context_payload
)
end
if
logging
# TODO: this logic could migrate into `Gitlab::ExceptionLogFormatter`
# and we could also flatten deep nested hashes if required for search
# (e.g. if `extra` includes hash of hashes).
# In the current implementation, we don't flatten multi-level folded hashes.
log_hash
=
{}
Raven
.
context
.
tags
.
each
{
|
name
,
value
|
log_hash
[
"tags.
#{
name
}
"
]
=
value
}
Raven
.
context
.
user
.
each
{
|
name
,
value
|
log_hash
[
"user.
#{
name
}
"
]
=
value
}
Raven
.
context
.
extra
.
merge
(
extra
).
each
{
|
name
,
value
|
log_hash
[
"extra.
#{
name
}
"
]
=
value
}
Gitlab
::
ExceptionLogFormatter
.
format!
(
exception
,
log_hash
)
formatter
=
Gitlab
::
ErrorTracking
::
LogFormatter
.
new
log_hash
=
formatter
.
generate_log
(
exception
,
context_payload
)
Gitlab
::
ErrorTracking
::
Logger
.
error
(
log_hash
)
end
end
def
sanitize_request_parameters
(
parameters
)
filter
=
ActiveSupport
::
ParameterFilter
.
new
(
::
Rails
.
application
.
config
.
filter_parameters
)
filter
.
filter
(
parameters
)
end
def
sentry_dsn
return
unless
Rails
.
env
.
production?
||
Rails
.
env
.
development?
return
unless
Gitlab
.
config
.
sentry
.
enabled
...
...
@@ -160,22 +126,6 @@ module Gitlab
Rails
.
env
.
development?
||
Rails
.
env
.
test?
end
def
default_tags
{
Labkit
::
Correlation
::
CorrelationId
::
LOG_KEY
.
to_sym
=>
Labkit
::
Correlation
::
CorrelationId
.
current_id
,
locale:
I18n
.
locale
}
end
# Static tags that are set on application start
def
extra_tags_from_env
Gitlab
::
Json
.
parse
(
ENV
.
fetch
(
'GITLAB_SENTRY_EXTRA_TAGS'
,
'{}'
)).
to_hash
rescue
=>
e
Gitlab
::
AppLogger
.
debug
(
"GITLAB_SENTRY_EXTRA_TAGS could not be parsed as JSON:
#{
e
.
class
.
name
}
:
#{
e
.
message
}
"
)
{}
end
# Group common, mostly non-actionable exceptions by type and message,
# rather than cause
def
custom_fingerprinting
(
event
,
ex
)
...
...
lib/gitlab/error_tracking/context_payload_generator.rb
0 → 100644
View file @
f2182208
# frozen_string_literal: true
module
Gitlab
module
ErrorTracking
class
ContextPayloadGenerator
def
self
.
generate
(
exception
,
extra
=
{})
new
.
generate
(
exception
,
extra
)
end
def
generate
(
exception
,
extra
=
{})
{
extra:
extra_payload
(
exception
,
extra
),
tags:
tags_payload
,
user:
user_payload
}
end
private
def
extra_payload
(
exception
,
extra
)
inline_extra
=
exception
.
try
(
:sentry_extra_data
)
if
inline_extra
.
present?
&&
inline_extra
.
is_a?
(
Hash
)
extra
=
extra
.
merge
(
inline_extra
)
end
sanitize_request_parameters
(
extra
)
end
def
sanitize_request_parameters
(
parameters
)
filter
=
ActiveSupport
::
ParameterFilter
.
new
(
::
Rails
.
application
.
config
.
filter_parameters
)
filter
.
filter
(
parameters
)
end
def
tags_payload
extra_tags_from_env
.
merge!
(
program:
Gitlab
.
process_name
,
locale:
I18n
.
locale
,
feature_category:
current_context
[
'meta.feature_category'
],
Labkit
::
Correlation
::
CorrelationId
::
LOG_KEY
.
to_sym
=>
Labkit
::
Correlation
::
CorrelationId
.
current_id
)
end
def
user_payload
{
username:
current_context
[
'meta.user'
]
}
end
# Static tags that are set on application start
def
extra_tags_from_env
Gitlab
::
Json
.
parse
(
ENV
.
fetch
(
'GITLAB_SENTRY_EXTRA_TAGS'
,
'{}'
)).
to_hash
rescue
=>
e
Gitlab
::
AppLogger
.
debug
(
"GITLAB_SENTRY_EXTRA_TAGS could not be parsed as JSON:
#{
e
.
class
.
name
}
:
#{
e
.
message
}
"
)
{}
end
def
current_context
# In case Gitlab::ErrorTracking is used when the app starts
return
{}
unless
defined?
(
::
Gitlab
::
ApplicationContext
)
::
Gitlab
::
ApplicationContext
.
current
.
to_h
end
end
end
end
lib/gitlab/error_tracking/log_formatter.rb
0 → 100644
View file @
f2182208
# frozen_string_literal: true
module
Gitlab
module
ErrorTracking
class
LogFormatter
# Note: all the accesses to Raven's contexts here are to keep the
# backward-compatibility to Sentry's built-in integrations. In future,
# they can be removed.
def
generate_log
(
exception
,
context_payload
)
payload
=
{}
Gitlab
::
ExceptionLogFormatter
.
format!
(
exception
,
payload
)
append_user_to_log!
(
payload
,
context_payload
)
append_tags_to_log!
(
payload
,
context_payload
)
append_extra_to_log!
(
payload
,
context_payload
)
payload
end
private
def
append_user_to_log!
(
payload
,
context_payload
)
user_context
=
Raven
.
context
.
user
.
merge
(
context_payload
[
:user
])
user_context
.
each
do
|
key
,
value
|
payload
[
"user.
#{
key
}
"
]
=
value
end
end
def
append_tags_to_log!
(
payload
,
context_payload
)
tags_context
=
Raven
.
context
.
tags
.
merge
(
context_payload
[
:tags
])
tags_context
.
each
do
|
key
,
value
|
payload
[
"tags.
#{
key
}
"
]
=
value
end
end
def
append_extra_to_log!
(
payload
,
context_payload
)
extra
=
Raven
.
context
.
extra
.
merge
(
context_payload
[
:extra
])
extra
=
extra
.
except
(
:server
)
# The extra value for sidekiq is a hash whose keys are strings.
if
extra
[
:sidekiq
].
is_a?
(
Hash
)
&&
extra
[
:sidekiq
].
key?
(
'args'
)
sidekiq_extra
=
extra
.
delete
(
:sidekiq
)
sidekiq_extra
[
'args'
]
=
Gitlab
::
ErrorTracking
::
Processor
::
SidekiqProcessor
.
loggable_arguments
(
sidekiq_extra
[
'args'
],
sidekiq_extra
[
'class'
]
)
payload
[
"extra.sidekiq"
]
=
sidekiq_extra
end
extra
.
each
do
|
key
,
value
|
payload
[
"extra.
#{
key
}
"
]
=
value
end
end
end
end
end
lib/gitlab/error_tracking/processor/context_payload_processor.rb
0 → 100644
View file @
f2182208
# frozen_string_literal: true
module
Gitlab
module
ErrorTracking
module
Processor
class
ContextPayloadProcessor
<
::
Raven
::
Processor
# This processor is added to inject application context into Sentry
# events generated by Sentry built-in integrations. When the
# integrations are re-implemented and use Gitlab::ErrorTracking, this
# processor should be removed.
def
process
(
payload
)
context_payload
=
Gitlab
::
ErrorTracking
::
ContextPayloadGenerator
.
generate
(
nil
,
{})
payload
.
deep_merge!
(
context_payload
)
end
end
end
end
end
lib/gitlab/exception_log_formatter.rb
View file @
f2182208
...
...
@@ -12,16 +12,6 @@ module Gitlab
'exception.message'
=>
exception
.
message
)
payload
.
delete
(
'extra.server'
)
payload
[
'extra.sidekiq'
].
tap
do
|
value
|
if
value
.
is_a?
(
Hash
)
&&
value
.
key?
(
'args'
)
value
=
value
.
dup
payload
[
'extra.sidekiq'
][
'args'
]
=
Gitlab
::
ErrorTracking
::
Processor
::
SidekiqProcessor
.
loggable_arguments
(
value
[
'args'
],
value
[
'class'
])
end
end
if
exception
.
backtrace
payload
[
'exception.backtrace'
]
=
Rails
.
backtrace_cleaner
.
clean
(
exception
.
backtrace
)
end
...
...
spec/frontend/environments/environments_app_spec.js
View file @
f2182208
...
...
@@ -97,13 +97,21 @@ describe('Environment', () => {
jest
.
spyOn
(
wrapper
.
vm
,
'
updateContent
'
).
mockImplementation
(()
=>
{});
wrapper
.
find
(
'
.gl-pagination li:nth-child(3) .page-link
'
).
trigger
(
'
click
'
);
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
'
available
'
,
page
:
'
2
'
});
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
'
available
'
,
page
:
'
2
'
,
nested
:
true
,
});
});
it
(
'
should make an API request when using tabs
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
,
'
updateContent
'
).
mockImplementation
(()
=>
{});
findEnvironmentsTabStopped
().
trigger
(
'
click
'
);
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
'
stopped
'
,
page
:
'
1
'
});
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
'
stopped
'
,
page
:
'
1
'
,
nested
:
true
,
});
});
it
(
'
should not make the same API request when clicking on the current scope tab
'
,
()
=>
{
...
...
spec/frontend/environments/folder/environments_folder_view_spec.js
View file @
f2182208
...
...
@@ -103,13 +103,18 @@ describe('Environments Folder View', () => {
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
wrapper
.
vm
.
scope
,
page
:
'
10
'
,
nested
:
true
,
});
});
it
(
'
should make an API request when using tabs
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
,
'
updateContent
'
).
mockImplementation
(()
=>
{});
findEnvironmentsTabStopped
().
trigger
(
'
click
'
);
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
'
stopped
'
,
page
:
'
1
'
});
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
'
stopped
'
,
page
:
'
1
'
,
nested
:
true
,
});
});
});
});
...
...
@@ -161,7 +166,11 @@ describe('Environments Folder View', () => {
it
(
'
should set page to 1
'
,
()
=>
{
jest
.
spyOn
(
wrapper
.
vm
,
'
updateContent
'
).
mockImplementation
(()
=>
{});
wrapper
.
vm
.
onChangeTab
(
'
stopped
'
);
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
'
stopped
'
,
page
:
'
1
'
});
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
'
stopped
'
,
page
:
'
1
'
,
nested
:
true
,
});
});
});
...
...
@@ -172,6 +181,7 @@ describe('Environments Folder View', () => {
expect
(
wrapper
.
vm
.
updateContent
).
toHaveBeenCalledWith
({
scope
:
wrapper
.
vm
.
scope
,
page
:
'
4
'
,
nested
:
true
,
});
});
});
...
...
spec/lib/gitlab/error_tracking/context_payload_generator_spec.rb
0 → 100644
View file @
f2182208
# frozen_string_literal: true
require
'fast_spec_helper'
require
'rspec-parameterized'
RSpec
.
describe
Gitlab
::
ErrorTracking
::
ContextPayloadGenerator
do
subject
(
:generator
)
{
described_class
.
new
}
let
(
:extra
)
do
{
some_other_info:
'info'
,
issue_url:
'http://gitlab.com/gitlab-org/gitlab-foss/-/issues/1'
}
end
let
(
:exception
)
{
StandardError
.
new
(
"Dummy exception"
)
}
before
do
allow
(
Labkit
::
Correlation
::
CorrelationId
).
to
receive
(
:current_id
).
and_return
(
'cid'
)
allow
(
I18n
).
to
receive
(
:locale
).
and_return
(
'en'
)
end
context
'user metadata'
do
let
(
:user
)
{
create
(
:user
)
}
it
'appends user metadata to the payload'
do
payload
=
{}
Gitlab
::
ApplicationContext
.
with_context
(
user:
user
)
do
payload
=
generator
.
generate
(
exception
,
extra
)
end
expect
(
payload
[
:user
]).
to
eql
(
username:
user
.
username
)
end
end
context
'tags metadata'
do
context
'when the GITLAB_SENTRY_EXTRA_TAGS env is not set'
do
before
do
stub_env
(
'GITLAB_SENTRY_EXTRA_TAGS'
,
nil
)
end
it
'does not log into AppLogger'
do
expect
(
Gitlab
::
AppLogger
).
not_to
receive
(
:debug
)
generator
.
generate
(
exception
,
extra
)
end
it
'does not send any extra tags'
do
payload
=
{}
Gitlab
::
ApplicationContext
.
with_context
(
feature_category:
'feature_a'
)
do
payload
=
generator
.
generate
(
exception
,
extra
)
end
expect
(
payload
[
:tags
]).
to
eql
(
correlation_id:
'cid'
,
locale:
'en'
,
program:
'test'
,
feature_category:
'feature_a'
)
end
end
context
'when the GITLAB_SENTRY_EXTRA_TAGS env is a JSON hash'
do
it
'includes those tags in all events'
do
stub_env
(
'GITLAB_SENTRY_EXTRA_TAGS'
,
{
foo:
'bar'
,
baz:
'quux'
}.
to_json
)
payload
=
{}
Gitlab
::
ApplicationContext
.
with_context
(
feature_category:
'feature_a'
)
do
payload
=
generator
.
generate
(
exception
,
extra
)
end
expect
(
payload
[
:tags
]).
to
eql
(
correlation_id:
'cid'
,
locale:
'en'
,
program:
'test'
,
feature_category:
'feature_a'
,
'foo'
=>
'bar'
,
'baz'
=>
'quux'
)
end
it
'does not log into AppLogger'
do
expect
(
Gitlab
::
AppLogger
).
not_to
receive
(
:debug
)
generator
.
generate
(
exception
,
extra
)
end
end
context
'when the GITLAB_SENTRY_EXTRA_TAGS env is not a JSON hash'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:env_var
,
:error
)
do
{
foo:
'bar'
,
baz:
'quux'
}.
inspect
|
'JSON::ParserError'
[].
to_json
|
'NoMethodError'
[
%w[foo bar]
].
to_json
|
'NoMethodError'
%w[foo bar]
.
to_json
|
'NoMethodError'
'"string"'
|
'NoMethodError'
end
with_them
do
before
do
stub_env
(
'GITLAB_SENTRY_EXTRA_TAGS'
,
env_var
)
end
it
'logs into AppLogger'
do
expect
(
Gitlab
::
AppLogger
).
to
receive
(
:debug
).
with
(
a_string_matching
(
error
))
generator
.
generate
({})
end
it
'does not include any extra tags'
do
payload
=
{}
Gitlab
::
ApplicationContext
.
with_context
(
feature_category:
'feature_a'
)
do
payload
=
generator
.
generate
(
exception
,
extra
)
end
expect
(
payload
[
:tags
]).
to
eql
(
correlation_id:
'cid'
,
locale:
'en'
,
program:
'test'
,
feature_category:
'feature_a'
)
end
end
end
end
context
'extra metadata'
do
it
'appends extra metadata to the payload'
do
payload
=
generator
.
generate
(
exception
,
extra
)
expect
(
payload
[
:extra
]).
to
eql
(
some_other_info:
'info'
,
issue_url:
'http://gitlab.com/gitlab-org/gitlab-foss/-/issues/1'
)
end
it
'appends exception embedded extra metadata to the payload'
do
allow
(
exception
).
to
receive
(
:sentry_extra_data
).
and_return
(
some_other_info:
'another_info'
,
mr_url:
'https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/1'
)
payload
=
generator
.
generate
(
exception
,
extra
)
expect
(
payload
[
:extra
]).
to
eql
(
some_other_info:
'another_info'
,
issue_url:
'http://gitlab.com/gitlab-org/gitlab-foss/-/issues/1'
,
mr_url:
'https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/1'
)
end
it
'filters sensitive extra info'
do
extra
[
:my_token
]
=
'456'
allow
(
exception
).
to
receive
(
:sentry_extra_data
).
and_return
(
mr_url:
'https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/1'
,
another_token:
'1234'
)
payload
=
generator
.
generate
(
exception
,
extra
)
expect
(
payload
[
:extra
]).
to
eql
(
some_other_info:
'info'
,
issue_url:
'http://gitlab.com/gitlab-org/gitlab-foss/-/issues/1'
,
mr_url:
'https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/1'
,
my_token:
'[FILTERED]'
,
another_token:
'[FILTERED]'
)
end
end
end
spec/lib/gitlab/error_tracking/log_formatter_spec.rb
0 → 100644
View file @
f2182208
# frozen_string_literal: true
require
'fast_spec_helper'
RSpec
.
describe
Gitlab
::
ErrorTracking
::
LogFormatter
do
let
(
:exception
)
{
StandardError
.
new
(
'boom'
)
}
let
(
:context_payload
)
do
{
server:
'local-hostname-of-the-server'
,
user:
{
ip_address:
'127.0.0.1'
,
username:
'root'
},
tags:
{
locale:
'en'
,
feature_category:
'category_a'
},
extra:
{
some_other_info:
'other_info'
,
sidekiq:
{
'class'
=>
'HelloWorker'
,
'args'
=>
[
'senstive string'
,
1
,
2
],
'another_field'
=>
'field'
}
}
}
end
before
do
Raven
.
context
.
user
[
:user_flag
]
=
'flag'
Raven
.
context
.
tags
[
:shard
]
=
'catchall'
Raven
.
context
.
extra
[
:some_info
]
=
'info'
allow
(
exception
).
to
receive
(
:backtrace
).
and_return
(
[
'lib/gitlab/file_a.rb:1'
,
'lib/gitlab/file_b.rb:2'
]
)
end
after
do
::
Raven
::
Context
.
clear!
end
it
'appends error-related log fields and filters sensitive Sidekiq arguments'
do
payload
=
described_class
.
new
.
generate_log
(
exception
,
context_payload
)
expect
(
payload
).
to
eql
(
'exception.class'
=>
'StandardError'
,
'exception.message'
=>
'boom'
,
'exception.backtrace'
=>
[
'lib/gitlab/file_a.rb:1'
,
'lib/gitlab/file_b.rb:2'
],
'user.ip_address'
=>
'127.0.0.1'
,
'user.username'
=>
'root'
,
'user.user_flag'
=>
'flag'
,
'tags.locale'
=>
'en'
,
'tags.feature_category'
=>
'category_a'
,
'tags.shard'
=>
'catchall'
,
'extra.some_other_info'
=>
'other_info'
,
'extra.some_info'
=>
'info'
,
"extra.sidekiq"
=>
{
"another_field"
=>
"field"
,
"args"
=>
[
"[FILTERED]"
,
"1"
,
"2"
],
"class"
=>
"HelloWorker"
}
)
end
end
spec/lib/gitlab/error_tracking/processor/context_payload_processor_spec.rb
0 → 100644
View file @
f2182208
# frozen_string_literal: true
require
'fast_spec_helper'
RSpec
.
describe
Gitlab
::
ErrorTracking
::
Processor
::
ContextPayloadProcessor
do
subject
(
:processor
)
{
described_class
.
new
}
before
do
allow_next_instance_of
(
Gitlab
::
ErrorTracking
::
ContextPayloadGenerator
)
do
|
generator
|
allow
(
generator
).
to
receive
(
:generate
).
and_return
(
user:
{
username:
'root'
},
tags:
{
locale:
'en'
,
program:
'test'
,
feature_category:
'feature_a'
,
correlation_id:
'cid'
},
extra:
{
some_info:
'info'
}
)
end
end
it
'merges the context payload into event payload'
do
payload
=
{
user:
{
ip_address:
'127.0.0.1'
},
tags:
{
priority:
'high'
},
extra:
{
sidekiq:
{
class:
'SomeWorker'
,
args:
[
'[FILTERED]'
,
1
,
2
]
}
}
}
processor
.
process
(
payload
)
expect
(
payload
).
to
eql
(
user:
{
ip_address:
'127.0.0.1'
,
username:
'root'
},
tags:
{
priority:
'high'
,
locale:
'en'
,
program:
'test'
,
feature_category:
'feature_a'
,
correlation_id:
'cid'
},
extra:
{
some_info:
'info'
,
sidekiq:
{
class:
'SomeWorker'
,
args:
[
'[FILTERED]'
,
1
,
2
]
}
}
)
end
end
spec/lib/gitlab/error_tracking_spec.rb
View file @
f2182208
This diff is collapsed.
Click to expand it.
spec/models/upload_spec.rb
View file @
f2182208
...
...
@@ -221,7 +221,7 @@ RSpec.describe Upload do
it
'does not send a message to Sentry'
do
upload
=
described_class
.
new
(
path:
"
#{
__FILE__
}
-nope"
,
store:
ObjectStorage
::
Store
::
LOCAL
)
expect
(
Raven
).
not_to
receive
(
:capture_message
)
expect
(
Gitlab
::
ErrorTracking
).
not_to
receive
(
:track_exception
)
upload
.
exist?
end
...
...
spec/requests/api/graphql/project/merge_requests_spec.rb
View file @
f2182208
This diff is collapsed.
Click to expand it.
spec/requests/api/helpers_spec.rb
View file @
f2182208
...
...
@@ -314,14 +314,13 @@ RSpec.describe API::Helpers do
expect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:sentry_dsn
).
and_return
(
Gitlab
.
config
.
sentry
.
dsn
)
Gitlab
::
ErrorTracking
.
configure
Raven
.
client
.
configuration
.
encoding
=
'json'
end
it
'does not report a MethodNotAllowed exception to Sentry'
do
exception
=
Grape
::
Exceptions
::
MethodNotAllowed
.
new
({
'X-GitLab-Test'
=>
'1'
})
allow
(
exception
).
to
receive
(
:backtrace
).
and_return
(
caller
)
expect
(
Raven
).
not_to
receive
(
:capture
_exception
).
with
(
exception
)
expect
(
Gitlab
::
ErrorTracking
).
not_to
receive
(
:track
_exception
).
with
(
exception
)
handle_api_exception
(
exception
)
end
...
...
@@ -330,8 +329,7 @@ RSpec.describe API::Helpers do
exception
=
RuntimeError
.
new
(
'test error'
)
allow
(
exception
).
to
receive
(
:backtrace
).
and_return
(
caller
)
expect
(
Raven
).
to
receive
(
:capture_exception
).
with
(
exception
,
tags:
a_hash_including
(
correlation_id:
'new-correlation-id'
),
extra:
{})
expect
(
Gitlab
::
ErrorTracking
).
to
receive
(
:track_exception
).
with
(
exception
)
Labkit
::
Correlation
::
CorrelationId
.
use_id
(
'new-correlation-id'
)
do
handle_api_exception
(
exception
)
...
...
@@ -357,20 +355,6 @@ RSpec.describe API::Helpers do
expect
(
json_response
[
'message'
]).
to
start_with
(
"
\n
RuntimeError (Runtime Error!):"
)
end
end
context
'extra information'
do
# Sentry events are an array of the form [auth_header, data, options]
let
(
:event_data
)
{
Raven
.
client
.
transport
.
events
.
first
[
1
]
}
it
'sends the params, excluding confidential values'
do
expect
(
ProjectsFinder
).
to
receive
(
:new
).
and_raise
(
'Runtime Error!'
)
get
api
(
'/projects'
,
user
),
params:
{
password:
'dont_send_this'
,
other_param:
'send_this'
}
expect
(
event_data
).
to
include
(
'other_param=send_this'
)
expect
(
event_data
).
to
include
(
'password=********'
)
end
end
end
describe
'.authenticate_non_get!'
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