8000 Update UA Parser to latest version by douglaspalmer · Pull Request #16876 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Update UA Parser to latest version - #16876

Merged
mposolda merged 1 commit into
keycloak:mainfrom
douglaspalmer:16729
Mar 8, 2023
Merged

mposolda merged 1 commit into
keycloak:mainfrom
douglaspalmer:16729

Conversation

@douglaspalmer
@douglaspalmer douglaspalmer commented Feb 6, 2023 •
Copy link
Copy Markdown
Contributor

closes #16729

@ghost ghost left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@ghost
ghost commented Feb 10, 2023
Copy link
Copy Markdown

Unreported flaky test detected

If the below flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.model.UserSessionProviderTest#testRestartSession

Keycloak CI - Base IT (6)

java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.keycloak.testsuite.model.UserSessionProviderTest.assertSession(UserSessionProviderTest.java:844)
...
java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.keycloak.testsuite.model.UserSessionProviderTest.assertSession(UserSessionProviderTest.java:844)
...

Report flaky test

@douglaspalmer
douglaspalmer force-pushed the 16729 branch 3 times, most recently from 7a70933 to 043d53d Compare February 10, 2023 23:34
@ghost ghost left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@ghost
ghost commented Feb 11, 2023
Copy link
Copy Markdown

Unreported flaky test detected

If the below flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.model.UserSessionProviderOfflineTest#testOnClientRemoved

Keycloak CI - Base IT (6)

java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.keycloak.testsuite.model.UserSessionProviderOfflineTest.assertSession(UserSessionProviderOfflineTest.java:454)
...
java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.keycloak.testsuite.model.UserSessionProviderOfflineTest.assertSession(UserSessionProviderOfflineTest.java:454)
...

Report flaky test

org.keycloak.testsuite.model.UserSessionProviderTest#testRestartSession

Keycloak CI - Base IT (6)

java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.keycloak.testsuite.model.UserSessionProviderTest.assertSession(UserSessionProviderTest.java:844)
...

Report flaky test

@douglaspalmer
douglaspalmer force-pushed the 16729 branch 4 times, most recently from 3930dcb to 59ee3b5 Compare February 13, 2023 23:51
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note that this step takes a few seconds.
It is common to instantiate the UserAgentAnalyzer once and use it many times.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@nielsbasjes Many thanks. I'm sure that will help with some of the performance issues we've been seeing.

@ghost
ghost commented Feb 14, 2023
Copy link
Copy Markdown

Unreported flaky test detected

If the below flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.model.UserSessionProviderOfflineTest#testOnClientRemoved

Keycloak CI - Base IT (6)

java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.keycloak.testsuite.model.UserSessionProviderOfflineTest.assertSession(UserSessionProviderOfflineTest.java:454)
...

Report flaky test

org.keycloak.testsuite.model.UserSessionProviderTest#testRestartSession

Keycloak CI - Base IT (6)

java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:87)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.junit.Assert.assertTrue(Assert.java:53)
	at org.keycloak.testsuite.model.UserSessionProviderTest.assertSession(UserSessionProviderTest.java:844)
...

Report flaky test

@ghost ghost left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@ghost ghost left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@ghost
ghost commented Feb 14, 2023
Copy link
Copy Markdown

Unreported flaky test detected

If the below flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.forms.LoginTest#loginRememberMeExpiredMaxLifespan

Keycloak CI - FIPS IT (non-strict)

java.lang.AssertionError: Expected LoginPage but was Keycloak Account Management (https://localhost:8543/auth/realms/test/account)
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.keycloak.testsuite.pages.AbstractPage.assertCurrent(AbstractPage.java:49)
	at jdk.internal.reflect.GeneratedMethodAccessor574.invoke(Unknown Source)
...
java.lang.AssertionError: Expected LoginPage but was Keycloak Account Management (https://localhost:8543/auth/realms/test/account)
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.keycloak.testsuite.pages.AbstractPage.assertCurrent(AbstractPage.java:49)
	at jdk.internal.reflect.GeneratedMethodAccessor574.invoke(Unknown Source)
...

Report flaky test

org.keycloak.testsuite.forms.LoginTest#loginRememberMeExpiredIdle

Keycloak CI - FIPS IT (non-strict)

java.lang.AssertionError: Expected LoginPage but was Keycloak Account Management (https://localhost:8543/auth/realms/test/account)
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.keycloak.testsuite.pages.AbstractPage.assertCurrent(AbstractPage.java:49)
	at jdk.internal.reflect.GeneratedMethodAccessor574.invoke(Unknown Source)
...
java.lang.AssertionError: Expected LoginPage but was Keycloak Account Management (https://localhost:8543/auth/realms/test/account)
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.assertTrue(Assert.java:42)
	at org.keycloak.testsuite.pages.AbstractPage.assertCurrent(AbstractPage.java:49)
	at jdk.internal.reflect.GeneratedMethodAccessor574.invoke(Unknown Source)
...

Report flaky test

@mposolda
Copy link
Copy Markdown
Contributor

@douglaspalmer I've started discussion related to device detection: #17067

@stianst
stianst commented Feb 14, 2023
Copy link
Copy Markdown
Contributor

I've reviewed and reported the reported flaky tests, nothing that is introduced by this PR, so from that perspective it's good to merge.

@mposolda mposolda left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@douglaspalmer I suggest that this is done in 2 pieces:

  1. First PR will only introduce SPI and change the current DeviceActivityManager to consume it. So the impl of that SPI can be still based on "ua parser" in that PR

  2. Follow-up PR, which will change default impl from "ua parser" to the yauaa.

This will allow easier review. Also the point is, that introduction of SPI can be always good IMO. However we're not yet 100% confident whether to go with yauaa (and hence it is question whether to go with also with (2)).

Also added 1 comment inline to the SPI.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible that this method is changed to something like DeviceRepresentation getDeviceRepresentation() ?

As it will be nice that SPI is generic and does not use any YAUAA specific stuff.

That will allow that for example people can plug their own impl based on completely different library if they want to.

@nielsbasjes
Copy link
Copy Markdown

@nielsbasjes is there something that can be improved on in terms of init time and memory footprint?

The only viable thing right now is to ask for less fields. This will make the engine drop all rules that are no longer needed. https://yauaa.basjes.nl/using/#limiting-to-only-certain-fields

And you can also drop all built in testcases during construction.

@douglaspalmer
douglaspalmer force-pushed the 16729 branch 2 times, most recently from 0cb99a0 to 064fc47 Compare February 16, 2023 16:47
@douglaspalmer
Copy link
Copy Markdown
Contributor Author

@nielsbasjes is there something that can be improved on in terms of init time and memory footprint?

The only viable thing right now is to ask for less fields. This will make the engine drop all rules that are no longer needed. https://yauaa.basjes.nl/using/#limiting-to-only-certain-fields

And you can also drop all built in testcases during construction.

How do I drop all built in testcases? I tried dropTests() but that results in an exception at startup:

Caused by: nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException: There were no resources found for the expression: UserAgents/Additional-Tests.yaml

@nielsbasjes
Copy link
Copy Markdown

And you can also drop all built in testcases during construction.

How do I drop all built in testcases? I tried dropTests() but that results in an exception at startup:

Caused by: nl.basjes.parse.useragent.analyze.InvalidParserConfigurationException: There were no resources found for the expression: UserAgents/Additional-Tests.yaml

I checked the full errorlog of your CI build.
Apparently there is a problem with the loading of the resources in the normal way (i.e. usually something with classloading). So in Yauaa the system fallsback to the builtin list of all resources and tries to load those. And apparently I do not handle that in combination with the dropTests() correctly.

So I created nielsbasjes/yauaa#927

@douglaspalmer
douglaspalmer force-pushed the 16729 branch 2 times, most recently from 3bbe17e to d153d1e Compare February 21, 2023 15:59
@nielsbasjes
Copy link
Copy Markdown

I fixed the dropTests problem in Yauaa 7.14.0 (released just now).

@douglaspalmer douglaspalmer changed the title Replace UA Parser with YAUAA Update UA Parser to latest version Mar 1, 2023
@mposolda
mposolda commented Mar 7, 2023
Copy link
Copy Markdown
Contributor

@douglaspalmer LGTM, Thanks!

Question: You mentioned in the initial comment on this PR Marking as draft because there are still a couple of test failures and a performance degradation to discuss. . Am I assume correctly that this was related to yauaa, but not anymore related to latest version of this PR with latest ua_parser? So is this PR ready to be merged as is from your point of view?

@mposolda
mposolda marked this pull request as ready for review March 7, 2023 14:22
@mposolda
mposolda requested a review from a team as a code owner March 7, 2023 14:22
@abstractj
abstractj requested review from nielsbasjes and stianst March 7, 2023 18:44
@abstractj abstractj left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mposolda looks good to merge, unless @stianst has some additional comments.

@nielsbasjes
Copy link
Copy Markdown

I was asked for a review but I have no say in this project.
I am curious which aspects of my project Yauaa made you choose to stay with your current solution.

@douglaspalmer
Copy link
Copy Markdown
Contributor Author

I was asked for a review but I have no say in this project.
I am curious which aspects of my project Yauaa made you choose to stay with your current solution.

@nielsbasjes Performance was the main issue. You can read the discussion here: #17067

@nielsbasjes
Copy link
Copy Markdown

Thanks.

@mposolda
mposolda commented Mar 8, 2023
Copy link
Copy Markdown
Contributor

@douglaspalmer @abstractj @nielsbasjes Thanks everyone to participate in this!
@nielsbasjes Good luck with the yauaa project. Maybe we will be able to leverage in the future, but sorry that not now... At least due the recently added SPI, it is possible for people to replace the ua_parser based impl with the other one (for example yauaa) by implementing Provider and deploy it to Keycloak. If you're interested in providing something like that, here is the list of Keycloak extensions https://www.keycloak.org/extensions.html - we can add your extension if you prefer.

@mposolda
mposolda merged commit 181e1b9 into keycloak:main Mar 8, 2023
@nielsbasjes
Copy link
Copy Markdown

@mposolda I'll have a look at making it an extension.

Regarding #17067
I found the reason behind the performance difference between ua-parser and yauaa: the cache used by ua-parser is not threadsafe (unsynchronized LRUMap) and the one used with yauaa is threadsafe (Caffeine).

See also: #17067 (comment)

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.

Dependency review: UA Parser

5 participants

0