Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement search by pattern for Mapping Rules #1239

Merged
merged 2 commits into from
Sep 27, 2019
Merged

Conversation

duduribeiro
Copy link
Contributor

This commit implements a search by pattern for mapping rules. It
includes a search field in the mapping rules page for both Backend
APIs and Services. It also adds an index for ProxyRule class using
Sphinx.

@thomasmaas
Copy link
Member

Screen capture?

@duduribeiro
Copy link
Contributor Author

search

@thomasmaas ☝️

@duduribeiro
Copy link
Contributor Author

search_2

@duduribeiro duduribeiro force-pushed the search_mapping_rules branch 4 times, most recently from 681a8b1 to 3c11f33 Compare September 26, 2019 00:50
Martouta
Martouta previously approved these changes Sep 26, 2019
Copy link
Contributor

@Martouta Martouta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 🥇 💪

@Martouta Martouta dismissed their stale review September 26, 2019 07:53

Needs some polishing :)

app/models/proxy_rule.rb Outdated Show resolved Hide resolved
@@ -25,6 +28,16 @@ class ProxyRule < ApplicationRecord

ALLOWED_HTTP_METHODS = %w[GET POST DELETE PUT PATCH HEAD OPTIONS].freeze

scope :by_query, ->(query, owner_type, owner_id) do
return if query.blank?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return if query.blank?
return none if query.blank?

Not sure if it will work, but then this way we return the same time and we can chain scopes... so it won't be null anymore. Btw, lambda checks that the params are passed so 'query' should never be nil 🤔 so imo we shouldn't even have this checking the type at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first shoot was returning a none relation. But it doesn't work because it ignores prepended and postponed relations in the query. eg:

with return none ..

[1] pry(main)> ProxyRule.by_query('', 'Proxy', 22).where(position: 2).to_sql
=> ""

it returned the empty relation and ignored the where position.

with return nil

[1] pry(main)> ProxyRule.by_query('', 'Proxy', 22).where(position: 2).to_sql
=> "SELECT `proxy_rules`.* FROM `proxy_rules` WHERE `proxy_rules`.`position` = 2"

it skipped the where(id: ..) and made the where(position: ) one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a query see app/queries I prefer not mixing scopes with other stuffs.

app/models/proxy_rule.rb Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 26, 2019

Codecov Report

Merging #1239 into master will increase coverage by 5.24%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1239      +/-   ##
==========================================
+ Coverage   86.29%   91.54%   +5.24%     
==========================================
  Files        2139     2265     +126     
  Lines       66794    73359    +6565     
==========================================
+ Hits        57640    67154    +9514     
+ Misses       9154     6205    -2949
Impacted Files Coverage Δ
app/controllers/api/proxy_rules_controller.rb 90.32% <100%> (+38.59%) ⬆️
app/indices/proxy_rules_index.rb 100% <100%> (ø)
app/workers/index_proxy_rule_worker.rb 100% <100%> (ø)
...der/admin/backend_apis/mapping_rules_controller.rb 52.17% <100%> (+7.17%) ⬆️
app/models/proxy_rule.rb 98.73% <100%> (+0.12%) ⬆️
app/controllers/proxy_rule_shared_controller.rb 100% <100%> (+40%) ⬆️
config/routes.rb 98.06% <100%> (ø) ⬆️
app/lib/csv/applications_exporter.rb 16% <0%> (-84%) ⬇️
...ce_discovery/import_cluster_definitions_service.rb 32.3% <0%> (-67.7%) ⬇️
app/workers/audited_worker.rb 42.85% <0%> (-57.15%) ⬇️
... and 880 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c00e32...3745336. Read the comment docs.

@Martouta Martouta self-requested a review September 26, 2019 13:50
@duduribeiro duduribeiro force-pushed the search_mapping_rules branch 3 times, most recently from d6384bf to 04017d5 Compare September 26, 2019 19:37
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 😂 😂 😂 😂
Cadu 1 - RuboCop 0

@@ -36,6 +36,10 @@ def initialize(a,b,c)

transactional = non_transactional.map {|t| "~#{t}" }

Before do
IndexProxyRuleWorker.stubs(:perform_later)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Martouta
It is run after_commit, so all tests with disable_transactional_fixtures and involving Proxy (basically all, because you create an account + service + proxy) will trigger indexation of Proxy.

We wanted to use ActiveJob::TestHelper perform_enqueued_jobs but it does not have the :only options in Rails 4.2, we need to update to rails 5.x (see the monkey patch)

And anyway it is big task to change it everywhere, so it is acceptable to have it now
We need to move all workers to ActiveJob, not the purpose of this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, cucumber enables Sidekiq.inline! for all features, without this, all cucumber tests fails

# TODO: Remove this Monkey patch after we move to Rails 5.
# This is used to ensure that we run only a specific job in a Test.
# It was extracted from
# https://github.com/rails/rails/blob/fc5dd0b85189811062c85520fd70de8389b55aeb/activejob/lib/active_job/test_helper.rb#L368
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is acceptable! Really :)

Copy link
Contributor

@hallelujah hallelujah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better idea not to mix models scopes and search queries

@Martouta
Copy link
Contributor

Since you are going to push again anyway, personally I'd appreciate if the update/install of Gems could be a separate commit before the actual changes in the code 😄

This commit upgrades thinking sphinx gem. The new version added
the ability to filter using string types, avoinding us to save it
using a CRC32 version of the string.

This commit also upgrades minitest.
@duduribeiro duduribeiro force-pushed the search_mapping_rules branch 3 times, most recently from e348ef0 to e9c43b7 Compare September 27, 2019 14:57
Martouta
Martouta previously approved these changes Sep 27, 2019
Copy link
Contributor

@Martouta Martouta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing job! 👏 🥇 💪

thomasmaas
thomasmaas previously approved these changes Sep 27, 2019
scope = scope.order_by(@sort, @direction).includes(:metric)
return scope if query.blank?
options = {
ids_only: true, star: true, per_page: 1_000_000, ignore_scopes: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 million per page? Are you sure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.. don't make sense haha.. will add the same maximum as we paginate.

scope = scope.order_by(@sort, @direction).includes(:metric)
return scope if query.blank?
options = {
ids_only: true, star: true, per_page: 20, ignore_scopes: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch I dis not check correctly
The per page does not use the variable in. Initialize

This commit implements a search by pattern for mapping rules. It
includes a search field in the mapping rules page for both Backend
APIs and Services. It also adds an index for ProxyRule class using
Sphinx.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants