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
24a1e42c
Commit
24a1e42c
authored
Jul 06, 2021
by
Gary Holtz
Committed by
Michael Kozono
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a feature flag to change maximum text highlight size to 1MB
parent
83a7eb42
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
4 deletions
+27
-4
config/feature_flags/development/one_megabyte_file_size_limit.yml
...eature_flags/development/one_megabyte_file_size_limit.yml
+8
-0
lib/gitlab/highlight.rb
lib/gitlab/highlight.rb
+12
-4
spec/lib/gitlab/highlight_spec.rb
spec/lib/gitlab/highlight_spec.rb
+7
-0
No files found.
config/feature_flags/development/one_megabyte_file_size_limit.yml
0 → 100644
View file @
24a1e42c
---
name
:
one_megabyte_file_size_limit
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65167
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/334916
milestone
:
'
14.1'
type
:
development
group
:
group::code review
default_enabled
:
false
lib/gitlab/highlight.rb
View file @
24a1e42c
...
@@ -11,11 +11,9 @@ module Gitlab
...
@@ -11,11 +11,9 @@ module Gitlab
end
end
def
self
.
too_large?
(
size
)
def
self
.
too_large?
(
size
)
file_size_limit
=
Gitlab
.
config
.
extra
[
'maximum_text_highlight_size_kilobytes'
]
return
false
unless
size
.
to_i
>
self
.
file_size_limit
return
false
unless
size
.
to_i
>
file_size_limit
over_highlight_size_limit
.
increment
(
source:
"file size:
#{
self
.
file_size_limit
}
"
)
if
Feature
.
enabled?
(
:track_file_size_over_highlight_limit
)
over_highlight_size_limit
.
increment
(
source:
"file size:
#{
file_size_limit
}
"
)
if
Feature
.
enabled?
(
:track_file_size_over_highlight_limit
)
true
true
end
end
...
@@ -51,6 +49,16 @@ module Gitlab
...
@@ -51,6 +49,16 @@ module Gitlab
attr_reader
:context
attr_reader
:context
def
self
.
file_size_limit
if
Feature
.
enabled?
(
:one_megabyte_file_size_limit
)
1024
.
kilobytes
else
Gitlab
.
config
.
extra
[
'maximum_text_highlight_size_kilobytes'
]
end
end
private_class_method
:file_size_limit
def
custom_language
def
custom_language
return
unless
@language
return
unless
@language
...
...
spec/lib/gitlab/highlight_spec.rb
View file @
24a1e42c
...
@@ -50,9 +50,16 @@ RSpec.describe Gitlab::Highlight do
...
@@ -50,9 +50,16 @@ RSpec.describe Gitlab::Highlight do
let
(
:result
)
{
described_class
.
highlight
(
file_name
,
content
)
}
# content is 44 bytes
let
(
:result
)
{
described_class
.
highlight
(
file_name
,
content
)
}
# content is 44 bytes
before
do
before
do
stub_feature_flags
(
one_megabyte_file_size_limit:
false
)
stub_config
(
extra:
{
'maximum_text_highlight_size_kilobytes'
=>
0.0001
}
)
# 1.024 bytes
stub_config
(
extra:
{
'maximum_text_highlight_size_kilobytes'
=>
0.0001
}
)
# 1.024 bytes
end
end
it
'confirm file size is 1MB when `one_megabyte_file_size_limit` is enabled'
do
stub_feature_flags
(
one_megabyte_file_size_limit:
true
)
expect
(
described_class
.
too_large?
(
1024
.
kilobytes
)).
to
eq
(
false
)
expect
(
described_class
.
too_large?
(
1025
.
kilobytes
)).
to
eq
(
true
)
end
it
'increments the metric for oversized files'
do
it
'increments the metric for oversized files'
do
expect
{
result
}.
to
change
{
over_highlight_size_limit
(
'file size: 0.0001'
)
}.
by
(
1
)
expect
{
result
}.
to
change
{
over_highlight_size_limit
(
'file size: 0.0001'
)
}.
by
(
1
)
end
end
...
...
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