Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2021-03-08 00:09:10 +00:00
parent 4660a51d93
commit 0b48416b38
7 changed files with 70 additions and 25 deletions

View file

@ -5,6 +5,7 @@ import {
GlButtonGroup, GlButtonGroup,
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
GlFormCheckbox,
GlSprintf, GlSprintf,
GlLink, GlLink,
GlTooltipDirective, GlTooltipDirective,
@ -81,6 +82,7 @@ export default {
GlButtonGroup, GlButtonGroup,
GlDropdown, GlDropdown,
GlDropdownItem, GlDropdownItem,
GlFormCheckbox,
GlSkeletonLoader, GlSkeletonLoader,
MergeTrainHelperText: () => MergeTrainHelperText: () =>
import('ee_component/vue_merge_request_widget/components/merge_train_helper_text.vue'), import('ee_component/vue_merge_request_widget/components/merge_train_helper_text.vue'),
@ -495,16 +497,15 @@ export default {
</gl-button-group> </gl-button-group>
<div class="media-body-wrap space-children"> <div class="media-body-wrap space-children">
<template v-if="shouldShowMergeControls"> <template v-if="shouldShowMergeControls">
<label v-if="canRemoveSourceBranch"> <gl-form-checkbox
<input v-if="canRemoveSourceBranch"
id="remove-source-branch-input" id="remove-source-branch-input"
v-model="removeSourceBranch" v-model="removeSourceBranch"
:disabled="isRemoveSourceBranchButtonDisabled" :disabled="isRemoveSourceBranchButtonDisabled"
class="js-remove-source-branch-checkbox" class="js-remove-source-branch-checkbox gl-min-h-7 gl-display-flex gl-align-items-center gl-mr-2"
type="checkbox" >
/>
{{ __('Delete source branch') }} {{ __('Delete source branch') }}
</label> </gl-form-checkbox>
<!-- Placeholder for EE extension of this component --> <!-- Placeholder for EE extension of this component -->
<squash-before-merge <squash-before-merge

View file

@ -44,7 +44,7 @@ export default {
:checked="value" :checked="value"
:disabled="isDisabled" :disabled="isDisabled"
name="squash" name="squash"
class="qa-squash-checkbox js-squash-checkbox gl-mb-0 gl-mr-2" class="qa-squash-checkbox js-squash-checkbox gl-min-h-7 gl-display-flex gl-align-items-center gl-mr-2"
:title="tooltipTitle" :title="tooltipTitle"
@change="(checked) => $emit('input', checked)" @change="(checked) => $emit('input', checked)"
> >

View file

@ -62,16 +62,16 @@ The following languages and dependency managers are supported:
| Package Managers | Languages | Supported files | Scan tools | | Package Managers | Languages | Supported files | Scan tools |
| ------------------- | --------- | --------------- | ------------ | | ------------------- | --------- | --------------- | ------------ |
| [Bundler](https://bundler.io/) | Ruby | `Gemfile.lock`, `gems.locked` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium), [bundler-audit](https://github.com/rubysec/bundler-audit) | | [Bundler](https://bundler.io/) | Ruby | `Gemfile.lock`, `gems.locked` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium), [bundler-audit](https://github.com/rubysec/bundler-audit) |
| [Composer](https://getcomposer.org/) | PHP | `composer.lock` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium) | | [Composer](https://getcomposer.org/) | PHP | `composer.lock` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) |
| [Conan](https://conan.io/) | C, C++ | [`conan.lock`](https://docs.conan.io/en/latest/versioning/lockfiles.html) | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium) | | [Conan](https://conan.io/) | C, C++ | [`conan.lock`](https://docs.conan.io/en/latest/versioning/lockfiles.html) | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) |
| [Golang](https://golang.org/) | Go | `go.sum` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium) | | [Golang](https://golang.org/) | Go | `go.sum` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) |
| [Gradle](https://gradle.org/), [Maven](https://maven.apache.org/) | Java | `build.gradle`, `build.gradle.kts`, `pom.xml` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium) | | [Gradle](https://gradle.org/), [Maven](https://maven.apache.org/) | Java | `build.gradle`, `build.gradle.kts`, `pom.xml` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) |
| [npm](https://www.npmjs.com/), [yarn](https://classic.yarnpkg.com/en/) 1.x | JavaScript | `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium) | | [npm](https://www.npmjs.com/), [yarn](https://classic.yarnpkg.com/en/) 1.x | JavaScript | `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) |
| [npm](https://www.npmjs.com/) (7 and earlier), [yarn](https://classic.yarnpkg.com/en/) 1.x | JavaScript | `package.json` | [Retire.js](https://retirejs.github.io/retire.js/) | | [npm](https://www.npmjs.com/) (7 and earlier), [yarn](https://classic.yarnpkg.com/en/) 1.x | JavaScript | `package.json` | [Retire.js](https://retirejs.github.io/retire.js/) |
| [NuGet](https://www.nuget.org/) 4.9+ | .NET, C# | [`packages.lock.json`](https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#enabling-lock-file) | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium) | | [NuGet](https://www.nuget.org/) 4.9+ | .NET, C# | [`packages.lock.json`](https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#enabling-lock-file) | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) |
| [`setuptools`](https://setuptools.readthedocs.io/en/latest/), [pip](https://pip.pypa.io/en/stable/), [Pipenv](https://pipenv.pypa.io/en/latest/) (*1*) | Python | `setup.py`, `requirements.txt`, `requirements.pip`, `requires.txt`, `Pipfile`, `Pipfile.lock` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium) | | [`setuptools`](https://setuptools.readthedocs.io/en/latest/), [pip](https://pip.pypa.io/en/stable/), [Pipenv](https://pipenv.pypa.io/en/latest/) (*1*) | Python | `setup.py`, `requirements.txt`, `requirements.pip`, `requires.txt`, `Pipfile`, `Pipfile.lock` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) |
| [sbt](https://www.scala-sbt.org/) (*2*) | Scala | `build.sbt` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium) | | [sbt](https://www.scala-sbt.org/) (*2*) | Scala | `build.sbt` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) |
1. [Pipenv](https://pipenv.pypa.io/en/latest/) projects are scanned when a `Pipfile` is present. 1. [Pipenv](https://pipenv.pypa.io/en/latest/) projects are scanned when a `Pipfile` is present.
1. Support for [sbt](https://www.scala-sbt.org/) 1.3 and above was added in GitLab 13.9. 1. Support for [sbt](https://www.scala-sbt.org/) 1.3 and above was added in GitLab 13.9.
@ -80,7 +80,7 @@ Plans are underway for supporting the following languages, dependency managers,
| Package Managers | Languages | Supported files | Scan tools | Issue | | Package Managers | Languages | Supported files | Scan tools | Issue |
| ------------------- | --------- | --------------- | ---------- | ----- | | ------------------- | --------- | --------------- | ---------- | ----- |
| [Poetry](https://python-poetry.org/) | Python | `poetry.lock` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/gemnasium) | [GitLab#7006](https://gitlab.com/gitlab-org/gitlab/-/issues/7006) | | [Poetry](https://python-poetry.org/) | Python | `poetry.lock` | [Gemnasium](https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium) | [GitLab#7006](https://gitlab.com/gitlab-org/gitlab/-/issues/7006) |
## Contribute your scanner ## Contribute your scanner

View file

@ -6,9 +6,10 @@ module Gitlab
attach_to :active_record attach_to :active_record
def sql(event) def sql(event)
unless event.payload.fetch(:cached, event.payload[:name] == 'CACHE') return if !Transaction.current || event.payload.fetch(:cached, event.payload[:name] == 'CACHE')
Transaction.current&.increment
end Transaction.current.increment
Transaction.current.executed_sql(event.payload[:sql])
end end
end end
end end

View file

@ -15,6 +15,7 @@ module Gitlab
# the sake of keeping things simple we hardcode this value here, it's not # the sake of keeping things simple we hardcode this value here, it's not
# supposed to be changed very often anyway. # supposed to be changed very often anyway.
THRESHOLD = 100 THRESHOLD = 100
LOG_THRESHOLD = THRESHOLD * 1.5
# Error that is raised whenever exceeding the maximum number of queries. # Error that is raised whenever exceeding the maximum number of queries.
ThresholdExceededError = Class.new(StandardError) ThresholdExceededError = Class.new(StandardError)
@ -45,6 +46,7 @@ module Gitlab
@action = nil @action = nil
@count = 0 @count = 0
@whitelisted = false @whitelisted = false
@sql_executed = []
end end
# Sends a notification based on the number of executed SQL queries. # Sends a notification based on the number of executed SQL queries.
@ -60,6 +62,10 @@ module Gitlab
@count += 1 unless whitelisted @count += 1 unless whitelisted
end end
def executed_sql(sql)
@sql_executed << sql if @count <= LOG_THRESHOLD
end
def raise_error? def raise_error?
Rails.env.test? Rails.env.test?
end end
@ -71,8 +77,11 @@ module Gitlab
def error_message def error_message
header = 'Too many SQL queries were executed' header = 'Too many SQL queries were executed'
header = "#{header} in #{action}" if action header = "#{header} in #{action}" if action
msg = "a maximum of #{THRESHOLD} is allowed but #{count} SQL queries were executed"
log = @sql_executed.each_with_index.map { |sql, i| "#{i}: #{sql}" }.join("\n").presence
ellipsis = '...' if @count > LOG_THRESHOLD
"#{header}: a maximum of #{THRESHOLD} is allowed but #{count} SQL queries were executed" ["#{header}: #{msg}", log, ellipsis].compact.join("\n")
end end
end end
end end

View file

@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::QueryLimiting::ActiveSupportSubscriber do RSpec.describe Gitlab::QueryLimiting::ActiveSupportSubscriber do
let(:transaction) { instance_double(Gitlab::QueryLimiting::Transaction, increment: true) } let(:transaction) { instance_double(Gitlab::QueryLimiting::Transaction, executed_sql: true, increment: true) }
before do before do
allow(Gitlab::QueryLimiting::Transaction) allow(Gitlab::QueryLimiting::Transaction)
@ -18,6 +18,11 @@ RSpec.describe Gitlab::QueryLimiting::ActiveSupportSubscriber do
expect(transaction) expect(transaction)
.to have_received(:increment) .to have_received(:increment)
.once .once
expect(transaction)
.to have_received(:executed_sql)
.once
.with(String)
end end
context 'when the query is actually a rails cache hit' do context 'when the query is actually a rails cache hit' do
@ -30,6 +35,11 @@ RSpec.describe Gitlab::QueryLimiting::ActiveSupportSubscriber do
expect(transaction) expect(transaction)
.to have_received(:increment) .to have_received(:increment)
.once .once
expect(transaction)
.to have_received(:executed_sql)
.once
.with(String)
end end
end end
end end

View file

@ -118,6 +118,30 @@ RSpec.describe Gitlab::QueryLimiting::Transaction do
) )
end end
it 'includes a list of executed queries' do
transaction = described_class.new
transaction.count = max = described_class::THRESHOLD
%w[foo bar baz].each { |sql| transaction.executed_sql(sql) }
message = transaction.error_message
expect(message).to start_with(
"Too many SQL queries were executed: a maximum of #{max} " \
"is allowed but #{max} SQL queries were executed"
)
expect(message).to include("0: foo", "1: bar", "2: baz")
end
it 'indicates if the log is truncated' do
transaction = described_class.new
transaction.count = described_class::THRESHOLD * 2
message = transaction.error_message
expect(message).to end_with('...')
end
it 'includes the action name in the error message when present' do it 'includes the action name in the error message when present' do
transaction = described_class.new transaction = described_class.new
transaction.count = max = described_class::THRESHOLD transaction.count = max = described_class::THRESHOLD