From 6171b1dd0c6dd19b1dd85925b4a8cb0ae88164cd Mon Sep 17 00:00:00 2001 From: Kris Watson Date: Wed, 15 May 2024 12:09:14 -0700 Subject: [PATCH] Release 9.3.1 * Resolves a potential issue during container destruction. * Resolves an issue searching for large domains. * include node_id in metadata service * Updates to Monarx API. --- CHANGELOG.md | 14 +++++ VERSION | 2 +- app/controllers/admin/search_controller.rb | 2 +- app/controllers/search_controller.rb | 2 +- .../service_plugins/monarx_service_plugin.rb | 59 +++++++++---------- .../concerns/containers/container_metrics.rb | 2 + .../project_services/store_metadata.rb | 8 +-- .../20240509174702_update_project_metadata.rb | 8 +++ db/schema.rb | 2 +- 9 files changed, 59 insertions(+), 40 deletions(-) create mode 100644 db/migrate/20240509174702_update_project_metadata.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 65d1751..d7a9c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,34 @@ # Change Log +## v9.3.1 + +- [CHANGE] Include `node_id` in metadata service. +- [FIX] Fix global search for long url's. +- [FIX] Resolve issues with monarx API. + +*** + ## v9.3.0 - [FEATURE] Introducing Callbacks for the API. This allows you to receive a webhook from ComputeStacks when a api request is completed by a background worker. - [FEATURE] Move acme validation IP to a database field on the region. This allows different IPs for different regions. +*** + ## v9.2.2 - [FEATURE] Added volume and backups api. +*** + ## v9.2.1 - [FEATURE] `on_latest_image` Boolean field added to container and bastion api calls. If false, there is a new image on the node and a rebuild will use the new image. ## v9.2.0 +*** + **YJIT and JEMALLOC for ComputeStacks Production Environments** Please add the following to your `/etc/default/computestacks` file: diff --git a/VERSION b/VERSION index b13d146..3b74042 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.3.0 +9.3.1 diff --git a/app/controllers/admin/search_controller.rb b/app/controllers/admin/search_controller.rb index b070b07..bceb752 100644 --- a/app/controllers/admin/search_controller.rb +++ b/app/controllers/admin/search_controller.rb @@ -40,7 +40,7 @@ def create elsif uuid_regex.match?(@q) sparams[:volumes] = Volume.where(name: @q) sparams[:deployments] = Deployment.where(token: @q) - elsif @q.split('.').count == 4 # IP! + elsif @q =~ Resolv::IPv4::Regex # IP Address sparams[:cidr] = Network::Cidr.where(cidr: @q) + Node.where( Arel.sql(%Q(primary_ip = '#{@q}' OR public_ip = '#{@q}')) ) elsif q_filter == 'user' sparams[:users] = User.search_by @q diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index dbc7273..0acf805 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -19,7 +19,7 @@ def create if uuid_regex.match?(@q) sparams[:volumes] = Volume.find_all_for(current_user).where(name: @q) sparams[:deployments] = Deployment.find_all_for(current_user).where(token: @q) - elsif @q.split('.').count == 4 # IP! + elsif @q =~ Resolv::IPv4::Regex # IP Address sparams[:cidr] = Network::Cidr.where(cidr: @q) else sparams[:deployments] = Deployment.find_all_for(current_user).where Arel.sql %Q(lower(deployments.name) ~ '#{@q}') diff --git a/app/models/concerns/container_services/service_plugins/monarx_service_plugin.rb b/app/models/concerns/container_services/service_plugins/monarx_service_plugin.rb index 9db27b2..68d1d9f 100644 --- a/app/models/concerns/container_services/service_plugins/monarx_service_plugin.rb +++ b/app/models/concerns/container_services/service_plugins/monarx_service_plugin.rb @@ -55,28 +55,22 @@ def monarx_agent_id result = HTTP.timeout(30) .headers(container_image_plugin.monarx_api_headers) - .get "#{container_image_plugin.monarx_enterprise_url}/agent", params: { filter: "tags==#{container_service.name}" } + .get "#{container_image_plugin.monarx_enterprise_url}/agent", params: { filter: "all_tags==#{container_service.name}" } - if result.status.success? - begin - response = Oj.load result.body.to_s - rescue - return nil - end - return nil if response.dig("_embedded", "items").nil? - return nil if response["_embedded"]["items"].empty? - active_container_names = containers.pluck(:name) - mid = nil - response["_embedded"]["items"].each do |i| - if active_container_names.include?(i['host_id']) - mid = i['id'] - break - end - end - mid - else - nil + return nil unless result.status.success? + + begin + response = Oj.load result.body.to_s + rescue + return nil end + return nil if response.dig("_embedded", "items").nil? + return nil if response["_embedded"]["items"].empty? + + monarx_service = response["_embedded"]["items"].select { |i| container_service.name == i['host_id']}.first + return nil if monarx_service.nil? + + monarx_service["id"] end end @@ -85,19 +79,20 @@ def monarx_stats return nil if monarx_agent_id.nil? result = HTTP.timeout(30) .headers(container_image_plugin.monarx_api_headers) - .get "#{container_image_plugin.monarx_enterprise_url}/agent-file/metrics/agent-file-agent-classification", params: { filter: "agent_id==#{monarx_agent_id}"} - if result.status.success? - begin - response = Oj.load result.body.to_s - rescue - return nil - end - return nil if response.empty? - return nil if response[0]['counts'].nil? - response[0] - else - nil + .get "#{container_image_plugin.monarx_enterprise_url}/agent-file/metrics/agent-file-agent-classification", params: { filter: "all_tags==#{container_service.name}" } + + return nil unless result.status.success? + + begin + response = Oj.load result.body.to_s + rescue + return nil end + + return nil if response.empty? + return nil if response[0]['counts'].nil? + + response[0] end end diff --git a/app/models/concerns/containers/container_metrics.rb b/app/models/concerns/containers/container_metrics.rb index abcff1e..c94d073 100644 --- a/app/models/concerns/containers/container_metrics.rb +++ b/app/models/concerns/containers/container_metrics.rb @@ -148,6 +148,8 @@ def metric_mem_perc return 0.0 if m.nil? usage = (m[:memory] / Numeric::MEGABYTE) / memory (usage * 100).round(2) + rescue + 0.0 end def metric_mem_throttled(start_time, end_time) diff --git a/app/services/project_services/store_metadata.rb b/app/services/project_services/store_metadata.rb index 5290fd8..037dfc1 100644 --- a/app/services/project_services/store_metadata.rb +++ b/app/services/project_services/store_metadata.rb @@ -30,7 +30,7 @@ def overview_services s = [] deployment.services.each do |i| containers = i.containers.map do |c| - { id: c.id, name: c.name, ip: c.ip_address&.ipaddr } + { id: c.id, name: c.name, ip: c.ip_address&.ipaddr, node_id: c.node.id } end ingress_rules = i.ingress_rules.map do |c| { @@ -77,10 +77,10 @@ def overview_services category: i.container_image.category, tags: i.container_image.tags }, - containers: containers, - ingress_rules: ingress_rules, + containers:, + ingress_rules:, package: package_data, - settings: settings + settings: } end s diff --git a/db/migrate/20240509174702_update_project_metadata.rb b/db/migrate/20240509174702_update_project_metadata.rb new file mode 100644 index 0000000..0395923 --- /dev/null +++ b/db/migrate/20240509174702_update_project_metadata.rb @@ -0,0 +1,8 @@ +class UpdateProjectMetadata < ActiveRecord::Migration[7.1] + def change + Deployment.all.each do |i| + ProjectServices::StoreMetadata.new(i).perform + sleep 0.5 # Lets not flood consul too quickly. + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 97e7656..1aa4521 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_04_19_153846) do +ActiveRecord::Schema[7.1].define(version: 2024_05_09_174702) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "uuid-ossp"