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

Regex event detection #20907

Merged
merged 1 commit into from
Apr 8, 2021
Merged

Regex event detection #20907

merged 1 commit into from
Apr 8, 2021

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Dec 18, 2020

Part of #17201

Overview

The serialization of regular expressions in our yaml file is giving us issues when transitioning the data over json.
this breaks the react code that is transferring it

See issues in ManageIQ/manageiq-api#979

Solution

Store strings in yaml that are strings, but are detectable as being a regular expression.
This does transition the task of detecting it is a regular expression from yaml to ruby, but since that code already has special provisions for regular expression, it didn't seem to add too much additional knowledge.

Implementation

This is a single line change. but I had to do a little too much to get there.

Please look at individual commits to see what is the refactor and what is the actual change.

Tangent

I did not feel comfortable adding the regular expression logic in the loop. It is probably the same thing but this loop triggers events and needs to be as tight as possible.

It seems like we may be able to avoid this conversion every time. Especially since this is mostly relatively static. If we did that, we would see a big performance boost

@kbrock
Copy link
Member Author

kbrock commented Dec 18, 2020

sigh. stupid works for me locally test.
rubocops look like they are comparing old code even though git status shows that the branch is up to date.
pushing formatting changes and seeing if that fixes failed test.

app/models/event_stream.rb Outdated Show resolved Hide resolved
@Fryguy
Copy link
Member

Fryguy commented Jan 4, 2021

This will require changing the defaults in each of the providers. This feature was added specifically to allow providers to provide more sane defaults than listing out every single possible event (e.g. https://github.com/ManageIQ/manageiq-providers-redfish/blob/master/config/settings.yml#L8-L9)

We may also need a data migration if customers could change these. @agrare ?

app/models/event_stream.rb Outdated Show resolved Hide resolved
@Fryguy
Copy link
Member

Fryguy commented Jan 4, 2021

@agrare Please also review.

@kbrock kbrock force-pushed the regex_event_detection branch from 4dd431d to 5123806 Compare January 19, 2021 16:09
kbrock added a commit to kbrock/manageiq-providers-nuage that referenced this pull request Jan 19, 2021
part of ManageIQ/manageiq#20907

In order to better support json configuration settings, the regular
expressions in settings.yml are being converted to strings.
The event system is now responsible to handle the appropriately
kbrock added a commit to kbrock/manageiq-providers-azure_stack that referenced this pull request Jan 19, 2021
part of ManageIQ/manageiq#20907

In order to better support json configuration settings, the regular
expressions in settings.yml are being converted to strings.
The event system is now responsible to handle the appropriately
kbrock added a commit to kbrock/manageiq-providers-redfish that referenced this pull request Jan 19, 2021
part of ManageIQ/manageiq#20907

In order to better support json configuration settings, the regular
expressions in settings.yml are being converted to strings.
The event system is now responsible to handle the appropriately
kbrock added a commit to kbrock/manageiq-providers-redfish that referenced this pull request Jan 19, 2021
part of ManageIQ/manageiq#20907

In order to better support json configuration settings, the regular
expressions in settings.yml are being converted to strings.
The event system is now responsible to handle the appropriately
Copy link
Member

@Fryguy Fryguy left a comment

Choose a reason for hiding this comment

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

LGTM when mixed with the provider PRs.

Can you update the OP to put all the links to the provider PRs, and if you haven't already, can we run a cross-repo-test?

app/models/event_stream.rb Outdated Show resolved Hide resolved
Fryguy
Fryguy previously requested changes Jan 19, 2021
Copy link
Member

@Fryguy Fryguy left a comment

Choose a reason for hiding this comment

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

Actually, I'm looking closer and I think there's a bug -

I don't see any tests that actually test that the regex is being applied. The test from the regex just asks if it's in the list of filters to apply, but not if the filtering is actually being applied.

I have a feeling based on the code, that it's not actually working, because I don't see the code stripping off the leading and trailing / characters.

[1] pry(main)> "abc".match("b.")
=> #<MatchData "bc">
[1] pry(main)> "abc".match("/b./")
=> nil

@kbrock kbrock force-pushed the regex_event_detection branch from 5123806 to 5827ab8 Compare January 20, 2021 15:40
app/models/event_stream.rb Outdated Show resolved Hide resolved
@kbrock
Copy link
Member Author

kbrock commented Jan 20, 2021

miq-bot pushed a commit to ManageIQ/manageiq-cross_repo-tests that referenced this pull request Jan 20, 2021
before, events expressions are stored in yaml as regular expressions.
now, they are stored as a string with an opening/closing slash. Those
are treated as regular expressions.
@kbrock kbrock force-pushed the regex_event_detection branch from 5827ab8 to cdf4c28 Compare January 20, 2021 18:03
miq-bot pushed a commit to ManageIQ/manageiq-cross_repo-tests that referenced this pull request Jan 20, 2021
@miq-bot
Copy link
Member

miq-bot commented Jan 20, 2021

Checked commit kbrock@cdf4c28 with ruby 2.6.3, rubocop 0.82.0, haml-lint 0.35.0, and yamllint
2 files checked, 0 offenses detected
Everything looks fine. ⭐

@Fryguy
Copy link
Member

Fryguy commented Jan 21, 2021

The test from the regex just asks if it's in the list of filters to apply, but not if the filtering is actually being applied.

it 'returns the provider event if configured' do
expect(described_class.event_groups[:addition][:critical]).to include('CloneTaskEvent')
expect(described_class.event_groups[:addition][:critical]).to include(provider_event)
expect(described_class.event_groups[:addition][:warning]).to include(provider_regex)
end

@kbrock Can you verify if there are tests around this functionality, and if not can you add a couple?

Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

👍 looks great, much more targeted than the previous version

@Fryguy Fryguy self-requested a review February 8, 2021 15:09
@Fryguy Fryguy dismissed their stale review February 8, 2021 15:10

Overall LGTM...I still think it needs tests that exercise the actual regex.

@kbrock
Copy link
Member Author

kbrock commented Mar 30, 2021

The test from the regex just asks if it's in the list of filters to apply, but not if the filtering is actually being applied.

it 'returns the provider event if configured' do
expect(described_class.event_groups[:addition][:critical]).to include('CloneTaskEvent')
expect(described_class.event_groups[:addition][:critical]).to include(provider_event)
expect(described_class.event_groups[:addition][:warning]).to include(provider_regex)
end

@kbrock Can you verify if there are tests around this functionality, and if not can you add a couple?
-- @Fryguy

Not sure if I already answered this question out of band. We do have a test that ensures regular expressions are applied and in the right order. I feel that the regular expression behavior has not changed (should not change) so the existing test will do what we need.

it 'returns the group, level and group name of a regex-matched event' do
group, level = described_class.group_and_level('SomeMatchingEvent')
expect(group).to eq(:addition)
expect(level).to eq(:warning)
expect(described_class.group_name(group)).to eq('Creation/Addition')
end

@agrare
Copy link
Member

agrare commented Apr 7, 2021

@kbrock I want to confirm the merge order here, first this core pr, then the provider prs, then schema?

@kbrock
Copy link
Member Author

kbrock commented Apr 8, 2021

@agrare yea - I'd do nuage, core, then other providers.

You'd need to kick nuage again to ensure that it is green, but this order ensures the most green/happy builds
The schema can happen a the end with no rush.

if you prefer, we can change the code back to having core accept both inputs - so it would be green. Then we could remove at a later time when everything is green. (you and fry asked me to take that out. just offering if you have changed your mind)

@agrare
Copy link
Member

agrare commented Apr 8, 2021

Nuage is green here https://travis-ci.com/github/ManageIQ/manageiq-cross_repo-tests/builds/221501032 so I'm good with that

@agrare agrare closed this Apr 8, 2021
@agrare agrare reopened this Apr 8, 2021
@agrare agrare merged commit 7a0fe77 into ManageIQ:master Apr 8, 2021
@kbrock kbrock deleted the regex_event_detection branch April 9, 2021 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants