Commit Graph

45 Commits

Author SHA1 Message Date
GitLab Bot 61a82b8ec0 Add latest changes from gitlab-org/gitlab@master 2022-11-14 12:08:03 +00:00
GitLab Bot ed00b1a6a3 Add latest changes from gitlab-org/gitlab@master 2020-07-28 12:09:49 +00:00
GitLab Bot 95ab36cd97 Add latest changes from gitlab-org/gitlab@master 2020-05-15 21:08:21 +00:00
Sarah Yasonik e6fcdd7aca Update Metrics references to Object path
On reload, references to Metrics within classes in the Gitlab::Metrics
module fail. Update all references to ::Gitlab::Metrics so that
constant lookup finds the right module in development. This fix should
not impact production.
2019-02-14 18:05:35 +00:00
gfyoung 7ec8af5017 Enable even more frozen string for lib/gitlab
Enables frozen string for the following:

* lib/gitlab/hook_data/**/*.rb
* lib/gitlab/i18n/**/*.rb
* lib/gitlab/import/**/*.rb
* lib/gitlab/import_export/**/*.rb
* lib/gitlab/kubernetes/**/*.rb
* lib/gitlab/legacy_github_import/**/*.rb
* lib/gitlab/manifest_import/**/*.rb
* lib/gitlab/metrics/**/*.rb
* lib/gitlab/middleware/**/*.rb

Partially addresses gitlab-org/gitlab-ce#47424.
2018-11-16 17:41:14 -08:00
Lin Jen-Shin 4ee08b77bc Updates from `rubocop -a` 2018-07-09 21:13:08 +08:00
Pawel Chojnacki d4c768ce09 Rename Concern -> Methods 2018-01-29 15:13:05 +01:00
Pawel Chojnacki 938d9ffe40 Refactor metrics to use metrics dsl notation 2018-01-29 15:13:04 +01:00
Pawel Chojnacki 66c1acba0b Fix code after refactoring 2018-01-29 15:13:03 +01:00
Pawel Chojnacki d97548daa8 cleanup method call 2018-01-29 15:13:03 +01:00
Pawel Chojnacki e5d6141541 Actually make the new methods work 2018-01-29 15:13:03 +01:00
Pawel Chojnacki ef44fef15f Initiaal implementation of metrics concern 2018-01-29 15:13:03 +01:00
Oswaldo Ferreira 64c6a8ae6e Use Concurrent::AtomicReference instead AtomicFixnum 2017-12-26 17:23:12 -02:00
Douwe Maan 92e15071c1 Merge branch 'pawel/reduce_cardinality_of_prometheus_metrics' into 'master'
Reduce cardinality of some of GitLab's Prometheus metrics and fix observed duration reporting.

Closes #41045

See merge request gitlab-org/gitlab-ce!15881
2017-12-21 15:56:45 +00:00
Pawel Chojnacki 040167f072 Use seconds where possible, and convert to milliseconds for Influxdb consumption 2017-12-21 00:39:52 +01:00
Pawel Chojnacki ed715b7926 use in_milliseconds rails helper 2017-12-20 17:49:43 +01:00
Pawel Chojnacki 3c545133e8 Fix tests and formatting 2017-12-19 17:45:25 +01:00
Pawel Chojnacki 51668d3e1f Use class variable and add rubocop exception 2017-12-12 23:45:32 +01:00
Pawel Chojnacki da19ce625b Expire feature flag cache after 1minute 2017-12-12 18:52:08 +01:00
Pawel Chojnacki fd0a516854 use class variables instead of CONSTANTs 2017-12-12 18:38:28 +01:00
Pawel Chojnacki ca176a9bfe move call_measurement_enabled? method to the bottom of the file 2017-12-12 18:38:28 +01:00
Pawel Chojnacki 408208bc2b Use AtomicFixNum to implement CAS isolated cache update.
i.e.
Using compare and swap we update the expires_at value.
The thread that actually is able to update this value will also set
the cache holding method_call enabled state
2017-12-12 18:38:28 +01:00
Pawel Chojnacki 5904b033db Implemente measurement enabled cache using AtomicReference 2017-12-12 18:38:28 +01:00
Pawel Chojnacki 6af849644d Set cache expire only once the cache is filled,
to avoid situation where old result is returned in parallel thread.
2017-12-12 18:38:28 +01:00
Pawel Chojnacki b503e6ff42 Implement simple in memory cache that expires after 5 minutes 2017-12-12 18:38:28 +01:00
Pawel Chojnacki 53dc9e83c3 Cache feature check for 5 minutes for MethodCall instrumentation toggle 2017-12-12 18:38:28 +01:00
Pawel Chojnacki a8ebed6016 Make `System.monotonic_time` retun seconds represented by float with microsecond precision 2017-12-12 18:12:49 +01:00
Pawel Chojnacki 46cd2d93bb Use feature flag instead of application settigns to control if method calls should be instrumented 2017-11-23 23:39:10 +01:00
Pawel Chojnacki 0051b5fbcc Use only real duration to measure method call performance via Prometheus 2017-11-23 23:33:01 +01:00
Pawel Chojnacki efe4cab92b check method timing threshold when observing method performance 2017-11-23 23:33:01 +01:00
Pawel Chojnacki cdcbeaccbe Move prometheus middle ware to prometheus initialized. 2017-11-23 23:32:55 +01:00
Pawel Chojnacki 5a085dc126 Add missing mutex guard to method call metrics 2017-11-03 12:37:08 +01:00
Pawel Chojnacki 99881bb7b0 Move labels to be initialized in constructor 2017-11-02 18:11:44 +01:00
Pawel Chojnacki 44eedb22bc Add info about prometheus buckets
+ fix cpu time
2017-11-02 18:11:44 +01:00
Pawel Chojnacki b90bf88b14 Fix rspec errors, and add more tests to MethodCall and ActionView 2017-11-02 18:11:43 +01:00
Pawel Chojnacki 547dd817a5 Fix rubocop warnings 2017-11-02 18:11:43 +01:00
Pawel Chojnacki 815b8db1b9 Split call name to module and method name 2017-11-02 18:11:43 +01:00
Pawel Chojnacki cc7997d8d0 More parsable labels in method performance measurements 2017-11-02 18:11:43 +01:00
Pawel Chojnacki 29a1ad1646 Tune bucket sizes an action labels 2017-11-02 18:11:43 +01:00
Pawel Chojnacki 6db3151fa1 Introduce missing Action concept 2017-11-02 18:11:43 +01:00
Pawel Chojnacki 3cc28601f3 Cleanup sampling code and fix bug with samplers running without sleep 2017-11-02 18:10:57 +01:00
Pawel Chojnacki 3b1464803b Transaction and method instrumentation 2017-11-02 18:10:42 +01:00
Yorick Peterse 905f8d763a
Reduce instrumentation overhead
This reduces the overhead of the method instrumentation code primarily
by reducing the number of method calls. There are also some other small
optimisations such as not casting timing values to Floats (there's no
particular need for this), using Symbols for method call metric names,
and reducing the number of Hash lookups for instrumented methods.

The exact impact depends on the code being executed. For example, for a
method that's only called once the difference won't be very noticeable.
However, for methods that are called many times the difference can be
more significant.

For example, the loading time of a large commit
(nrclark/dummy_project@81ebdea5df)
was reduced from around 19 seconds to around 15 seconds using these
changes.
2016-07-28 16:56:17 +02:00
Yorick Peterse d7b4f36a3c
Use clock_gettime for all performance timestamps
Process.clock_gettime allows getting the real time in nanoseconds as
well as allowing one to get a monotonic timestamp. This offers greater
accuracy without the overhead of having to allocate a Time instance. In
general using Time.now/Time.new is about 2x slower than using
Process.clock_gettime(). For example:

    require 'benchmark/ips'

    Benchmark.ips do |bench|
      bench.report 'Time.now' do
        Time.now.to_f
      end

      bench.report 'clock_gettime' do
        Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
      end

      bench.compare!
    end

Running this benchmark gives:

    Calculating -------------------------------------
                Time.now   108.052k i/100ms
           clock_gettime   125.984k i/100ms
    -------------------------------------------------
                Time.now      2.343M (± 7.1%) i/s -     11.670M
           clock_gettime      4.979M (± 0.8%) i/s -     24.945M

    Comparison:
           clock_gettime:  4979393.8 i/s
                Time.now:  2342986.8 i/s - 2.13x slower

Another benefit of using Process.clock_gettime() is that we can simplify
the code a bit since it can give timestamps in nanoseconds out of the
box.
2016-06-28 17:51:25 +02:00
Yorick Peterse be3b878443 Track method call times/counts as a single metric
Previously we'd create a separate Metric instance for every method call
that would exceed the method call threshold. This is problematic because
it doesn't provide us with information to accurately get the _total_
execution time of a particular method. For example, if the method
"Foo#bar" was called 4 times with a runtime of ~10 milliseconds we'd end
up with 4 different Metric instances. If we were to then get the
average/95th percentile/etc of the timings this would be roughly 10
milliseconds. However, the _actual_ total time spent in this method
would be around 40 milliseconds.

To solve this problem we now create a single Metric instance per method.
This Metric instance contains the _total_ real/CPU time and the call
count for every instrumented method.
2016-06-17 13:09:55 -04:00