diff --git a/Dockerfile b/Dockerfile index 7c18e7af..96684475 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,7 @@ RUN dnf config-manager --setopt=ubi-8-*.exclude=net-snmp*,dracut*,libcom_err*,py http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages/centos-gpg-keys-8-2.el8.noarch.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \ dnf -y --disableplugin=subscription-manager module enable nodejs:12 && \ - dnf -y --disableplugin=subscription-manager module enable ruby:2.6 && \ + dnf -y --disableplugin=subscription-manager module enable ruby:2.7 && \ dnf clean all && \ rm -rf /var/cache/dnf diff --git a/Gemfile b/Gemfile index 193b0bbe..a71af9c2 100644 --- a/Gemfile +++ b/Gemfile @@ -6,9 +6,6 @@ gem 'rails', '~> 5.2.8', '>= 5.2.8.1' # Use PostgreSQL as the database for Active Record gem 'pg' -# InfluxDB for Github rate limit tracking -gem 'influxdb', '~>0.3.13' - # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0.7' diff --git a/Gemfile.lock b/Gemfile.lock index 5f72f1b9..42d3b8f3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,13 +145,10 @@ GEM hashdiff (1.0.1) i18n (1.12.0) concurrent-ruby (~> 1.0) - influxdb (0.3.17) - json jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.6.2) listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -360,7 +357,6 @@ DEPENDENCIES foreman (~> 0.64.0) haml (~> 5.1) haml_lint (~> 0.35.0) - influxdb (~> 0.3.13) jquery-rails listen manageiq-style diff --git a/README.md b/README.md index 83d4229a..7788c29c 100644 --- a/README.md +++ b/README.md @@ -197,21 +197,6 @@ underscores replaced with hyphens. repository with any rubocop problems, such as `MixedCaseConstant = 1`. Wait a few minutes and see if it comments on your PR. -### InfluxDB and Grafana setup - -The bot collects some optional data in a time series database -([InfluxDB](https://github.com/influxdata/influxdb)) and displays it in an -entirely separate user interface ([Grafana](http://grafana.org/)). - -To use these features: - -* Install and configure InfluxDB -* Enter the database name and credentials in your local settings yaml -* Install Grafana -* Enter the url of the running Grafana instance in your local settings yaml - -Metrics tracking is optional and you should not need to do these extra steps to run miq_bot locally. - ### Enabling and Disabling workers By default, most workers are enabled for all repos (except for the MergeTargetTitler diff --git a/config/settings.yml b/config/settings.yml index b4773309..e0aa671d 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -2,10 +2,6 @@ github_credentials: username: password: -influxdb_credentials: - database: - username: - password: # General settings grafana: diff --git a/lib/github_service/response/ratelimit_logger.rb b/lib/github_service/response/ratelimit_logger.rb index a2fc8506..439235b4 100644 --- a/lib/github_service/response/ratelimit_logger.rb +++ b/lib/github_service/response/ratelimit_logger.rb @@ -16,11 +16,6 @@ def initialize(app, logger = nil) def on_complete(env) api_calls_remaining = env.response_headers['x-ratelimit-remaining'] logger.info { "Executed #{env.method.to_s.upcase} #{env.url}...api calls remaining #{api_calls_remaining}" } - GithubUsageTracker.record_datapoint( - :requests_remaining => api_calls_remaining, - :uri => env.url.request_uri, - :timestamp => Time.parse(env.response_headers["date"]) - ) end end end diff --git a/lib/github_usage_tracker.rb b/lib/github_usage_tracker.rb deleted file mode 100644 index d96ac0e4..00000000 --- a/lib/github_usage_tracker.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'uri' - -class GithubUsageTracker - def self.record_datapoint(**args) - new.record_datapoint(args) - end - - def self.configured? - @configured ||= Settings.influxdb_credentials.to_hash.delete_blanks.present? - end - - def self.influxdb - @influx ||= InfluxDB::Client.new(Settings.influxdb_credentials.database, - :username => Settings.influxdb_credentials.username, - :password => Settings.influxdb_credentials.password, - :time_precision => 'ms') - end - - def record_datapoint(requests_remaining:, uri:, timestamp: Time.now) - return unless configured? - - request_uri = URI.parse(uri).path.chomp("/") - - values = { :tags => { :bot_version => MiqBot.version }, - :values => { :requests_remaining => requests_remaining.to_i, :uri => request_uri }, - :timestamp => (timestamp.to_f * 1000).to_i } # ms precision - - worker = worker_from_backtrace - values[:tags].merge!(:worker => worker) if worker - - influxdb.write_point('github_api_request', values) - rescue => e - Rails.logger.info("#{e.class}: #{e.message}") - end - - private - - delegate :influxdb, :configured?, :to => self - - def worker_from_backtrace - caller.each do |l| - match = /(?:app\/workers\/)(?:\w+\/)*?(\w+)(?:\.rb\:\d+)/.match(l) - return match[1] if match && match[1].exclude?("_mixin") - end - nil - end -end diff --git a/spec/lib/github_usage_tracker_spec.rb b/spec/lib/github_usage_tracker_spec.rb deleted file mode 100644 index 3806a3e0..00000000 --- a/spec/lib/github_usage_tracker_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -describe GithubUsageTracker do - subject(:tracker) { described_class.new } - let(:influxdb_client) { double } - let(:logger) { double(:info) } - - before do - allow(tracker).to receive(:configured?).and_return(true) - allow(tracker).to receive(:influxdb).and_return(influxdb_client) - stub_const("Rails", double(:logger => logger)) - stub_const("MiqBot", double(:version => "test")) - end - - describe "#record_datapoint" do - after do - tracker.record_datapoint(:requests_remaining => 1337, :uri => request_uri) - end - - context "with full URLs" do - let(:request_uri) { "https://api.github.com/orgs/ManageIQ" } - it "parses the URI correctly" do - expect(influxdb_client).to receive(:write_point) - .with('github_api_request', a_hash_including(:values => a_hash_including(:uri => "/orgs/ManageIQ"))) - end - end - - context "with full URLs, trailing slash" do - let(:request_uri) { "http://custom.githubdomain.com/orgs/ManageIQ/" } - it "parses the URI correctly" do - expect(influxdb_client).to receive(:write_point) - .with('github_api_request', a_hash_including(:values => a_hash_including(:uri => "/orgs/ManageIQ"))) - end - end - - context "with URI paths" do - let(:request_uri) { "/orgs/ManageIQ" } - it "parses the URI correctly" do - expect(influxdb_client).to receive(:write_point) - .with('github_api_request', a_hash_including(:values => a_hash_including(:uri => "/orgs/ManageIQ"))) - end - end - - context "with querystring" do - let(:request_uri) { "https://api.github.com/orgs/ManageIQ?some=thing&other=thing" } - it "parses the URI correctly" do - expect(influxdb_client).to receive(:write_point) - .with('github_api_request', a_hash_including(:values => a_hash_including(:uri => "/orgs/ManageIQ"))) - end - end - - context "with an invalid URI" do - let(:request_uri) { nil } - it "parses the URI correctly" do - expect(logger).to receive(:info).with(a_string_including("URI::InvalidURIError")) - end - end - end -end