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

[COST-5035] - Use json_query for OCP on GCP sql tag matching #5111

Merged
merged 6 commits into from
May 22, 2024
Merged

Conversation

lcouzens
Copy link
Contributor

@lcouzens lcouzens commented May 16, 2024

Jira Ticket

COST-5035

Description

This change will tweak our special case tag matching during OCP on GCP trino SQL to avoid false positives on generic string matching.

Testing

Manually run some trino sql:

  1. create table gcp_tag_test (tags varchar, matched_tag varchar);
  2. insert into gcp_tag_test (tags, matched_tag) values ('{"environment":"test","namespace":"fake-namespace"}', '');
  3. create table ocp_name_test (namespace varchar);
  4. insert into ocp_name_test (namespace) values ('test');
  5. Try to match the data!: SELECT gcp.tags, ocp.namespace, ((strpos(lower(gcp.tags), 'namespace') != 0 AND strpos(lower(gcp.tags), lower(ocp.namespace)) != 0)) AS match FROM gcp_tag_test AS gcp CROSS JOIN ocp_name_test AS ocp;
    tags | namespace | match
    -------------------------------------------------------------------------------------------------------+-----------+-------
    {"environment":"test","namespace":"fake-namespace"} | test | true

The above (OLD method) will match fine

Whereas the below (New) method fails to match (expected)

SELECT gcp.tags, ocp.namespace, (json_query(gcp.tags, 'strict $.namespace' OMIT QUOTES) = ocp.namespace) AS match FROM gcp_tag_test AS gcp CROSS JOIN ocp_name_test AS ocp;

{"environment":"test","namespace":"fake-namespace"} | test | false

You could also test a correct match by inserting the following:
insert into ocp_name_test (namespace) values ('fake-namespace');
Then run the above sql again

Release Notes

  • proposed release note
* [COST-5035](https://issues.redhat.com/browse/COST-5035) Fix ocp on gcp tag matching SQL

@lcouzens lcouzens added the gcp-smoke-tests pr_check will build the image and run gcp + ocp on gcp smoke tests label May 16, 2024
Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.2%. Comparing base (30d6721) to head (6a59d6f).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #5111   +/-   ##
=====================================
  Coverage   94.2%   94.2%           
=====================================
  Files        378     378           
  Lines      31622   31622           
  Branches    3756    3756           
=====================================
  Hits       29777   29777           
  Misses      1177    1177           
  Partials     668     668           

@lcouzens lcouzens marked this pull request as ready for review May 20, 2024 14:17
@lcouzens lcouzens requested review from a team as code owners May 20, 2024 14:17
djnakabaale
djnakabaale previously approved these changes May 20, 2024
@lcouzens
Copy link
Contributor Author

/retest

@lcouzens lcouzens enabled auto-merge (squash) May 22, 2024 22:27
@lcouzens lcouzens merged commit c21e5e5 into main May 22, 2024
11 checks passed
@lcouzens lcouzens deleted the COST-5035 branch May 22, 2024 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gcp-smoke-tests pr_check will build the image and run gcp + ocp on gcp smoke tests smokes-required
Projects
None yet
2 participants