summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-04-18 09:47:12 -0400
committerKamil Trzcinski <ayufan@ayufan.eu>2016-04-18 09:47:12 -0400
commit2ab8d3e652aaf00dc2d817f4840c5b2769271dc9 (patch)
tree263577926f546dca42f0d881655225ea93b8747a /lib
parent42102b4344027f104b71cd9c254cbd6025992544 (diff)
parentaca1e14bd39893be176222ccdb6e9d85799098e9 (diff)
downloadgitlab-ce-2ab8d3e652aaf00dc2d817f4840c5b2769271dc9.tar.gz
Merge branch 'after-script' into make-before-after-overridable
Diffstat (limited to 'lib')
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb40
-rw-r--r--lib/gitlab/metrics/instrumentation.rb37
2 files changed, 64 insertions, 13 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index 2738c9282b2..0414b790bbc 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -7,9 +7,9 @@ module Ci
ALLOWED_YAML_KEYS = [:before_script, :after_script, :image, :services, :types, :stages, :variables, :cache]
ALLOWED_JOB_KEYS = [:tags, :script, :only, :except, :type, :image, :services,
:allow_failure, :type, :stage, :when, :artifacts, :cache,
- :dependencies, :before_script, :after_script]
+ :dependencies, :before_script, :after_script, :variables]
- attr_reader :before_script, :after_script, :image, :services, :variables, :path, :cache
+ attr_reader :before_script, :after_script, :image, :services, :path, :cache
def initialize(config, path = nil)
@config = YAML.safe_load(config, [Symbol], [], true)
@@ -40,6 +40,17 @@ module Ci
@stages || DEFAULT_STAGES
end
+ def global_variables
+ @variables
+ end
+
+ def job_variables(name)
+ job = @jobs[name.to_sym]
+ return [] unless job
+
+ job.fetch(:variables, [])
+ end
+
private
def initial_parsing
@@ -136,7 +147,7 @@ module Ci
end
unless @variables.nil? || validate_variables(@variables)
- raise ValidationError, "variables should be a map of key-valued strings"
+ raise ValidationError, "variables should be a map of key-value strings"
end
validate_global_cache! if @cache
@@ -151,9 +162,25 @@ module Ci
raise ValidationError, "cache:untracked parameter should be an boolean"
end
+<<<<<<< HEAD
if @cache[:paths] && !validate_array_of_strings(@cache[:paths])
raise ValidationError, "cache:paths parameter should be an array of strings"
end
+=======
+ true
+ end
+
+ def validate_job!(name, job)
+ validate_job_name!(name)
+ validate_job_keys!(name, job)
+ validate_job_types!(name, job)
+
+ validate_job_stage!(name, job) if job[:stage]
+ validate_job_variables!(name, job) if job[:variables]
+ validate_job_cache!(name, job) if job[:cache]
+ validate_job_artifacts!(name, job) if job[:artifacts]
+ validate_job_dependencies!(name, job) if job[:dependencies]
+>>>>>>> origin/master
end
def validate_job_name!(name)
@@ -218,6 +245,13 @@ module Ci
end
end
+ def validate_job_variables!(name, job)
+ unless validate_variables(job[:variables])
+ raise ValidationError,
+ "#{name} job: variables should be a map of key-value strings"
+ end
+ end
+
def validate_job_cache!(name, job)
if job[:cache][:key] && !validate_string(job[:cache][:key])
raise ValidationError, "#{name} job: cache:key parameter should be a string"
diff --git a/lib/gitlab/metrics/instrumentation.rb b/lib/gitlab/metrics/instrumentation.rb
index face1921d2e..708ef79f304 100644
--- a/lib/gitlab/metrics/instrumentation.rb
+++ b/lib/gitlab/metrics/instrumentation.rb
@@ -11,6 +11,8 @@ module Gitlab
module Instrumentation
SERIES = 'method_calls'
+ PROXY_IVAR = :@__gitlab_instrumentation_proxy
+
def self.configure
yield self
end
@@ -91,6 +93,18 @@ module Gitlab
end
end
+ # Returns true if a module is instrumented.
+ #
+ # mod - The module to check
+ def self.instrumented?(mod)
+ mod.instance_variable_defined?(PROXY_IVAR)
+ end
+
+ # Returns the proxy module (if any) of `mod`.
+ def self.proxy_module(mod)
+ mod.instance_variable_get(PROXY_IVAR)
+ end
+
# Instruments a method.
#
# type - The type (:class or :instance) of method to instrument.
@@ -99,9 +113,8 @@ module Gitlab
def self.instrument(type, mod, name)
return unless Metrics.enabled?
- name = name.to_sym
- alias_name = :"_original_#{name}"
- target = type == :instance ? mod : mod.singleton_class
+ name = name.to_sym
+ target = type == :instance ? mod : mod.singleton_class
if type == :instance
target = mod
@@ -113,6 +126,12 @@ module Gitlab
method = mod.method(name)
end
+ unless instrumented?(target)
+ target.instance_variable_set(PROXY_IVAR, Module.new)
+ end
+
+ proxy_module = self.proxy_module(target)
+
# Some code out there (e.g. the "state_machine" Gem) checks the arity of
# a method to make sure it only passes arguments when the method expects
# any. If we were to always overwrite a method to take an `*args`
@@ -125,17 +144,13 @@ module Gitlab
args_signature = '*args, &block'
end
- send_signature = "__send__(#{alias_name.inspect}, #{args_signature})"
-
- target.class_eval <<-EOF, __FILE__, __LINE__ + 1
- alias_method #{alias_name.inspect}, #{name.inspect}
-
+ proxy_module.class_eval <<-EOF, __FILE__, __LINE__ + 1
def #{name}(#{args_signature})
trans = Gitlab::Metrics::Instrumentation.transaction
if trans
start = Time.now
- retval = #{send_signature}
+ retval = super
duration = (Time.now - start) * 1000.0
if duration >= Gitlab::Metrics.method_call_threshold
@@ -148,10 +163,12 @@ module Gitlab
retval
else
- #{send_signature}
+ super
end
end
EOF
+
+ target.prepend(proxy_module)
end
# Small layer of indirection to make it easier to stub out the current