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

Fixes #26046: Migrate compliance status from lift-json to zio-json #6086

Conversation

fanf
Copy link
Member

@fanf fanf commented Dec 16, 2024

https://issues.rudder.io/issues/26046

Main change:

  • upgrade to chimney 1.6.0 so that we can avoid ...withFieldComputed(_.a, _.aa.transformInto[AA]) and just use .withFieldRenamed(_.a, _.aa) given a transformer A to AA in scope
  • Tags needed to be migrated. Only encode is needed at that point, which was created with an intermediate JsonTag that is not exposed so that we can keep Tags in Json objects in place of JValue.
  • where the Json Lift objects were used directly, I mapped to the corresponding zio.json.ast objects
  • I introduced a OptPosNum type for compliance and compliance percent serialization. It's an Option[Numeric] (so that it works with int and float, but some quirks because js/java/scala) and so can be eliminated in the json when not present.
  • the json object ComplianceSerializable and ComplianceLevelSerialisation have their fields with the correct naming and order. There's a lot of chimney to map to/from the corresponding business objects.
  • I did on more time the encoding for AggregatedStatusReport (it already existed in a more compact fashion for database, now with full name - and IIRC, there's some other little differences)

⚠️ For now, we don't migrate RuleLine, because it's an horror mixing json and full js. And perhaps we can just delete it at some point.

I think other things are rather automatics.
Not a lot of net.liftweb.json removed, but still some more, especially in rudder-core.

@fanf fanf requested a review from clarktsiory December 16, 2024 07:05
@fanf fanf marked this pull request as draft December 16, 2024 07:05
@fanf fanf force-pushed the arch_26046/migrate_compliance_status_from_lift_json_to_zio_json branch from 485f1d2 to 94f34fa Compare December 16, 2024 21:54
@fanf fanf force-pushed the arch_26046/migrate_compliance_status_from_lift_json_to_zio_json branch from 94f34fa to f097743 Compare January 8, 2025 20:15
@fanf
Copy link
Member Author

fanf commented Jan 8, 2025

PR updated with a new commit

1 similar comment
@fanf
Copy link
Member Author

fanf commented Jan 8, 2025

PR updated with a new commit

@fanf fanf marked this pull request as ready for review January 8, 2025 22:12
@fanf fanf force-pushed the arch_26046/migrate_compliance_status_from_lift_json_to_zio_json branch from 9949e4e to e922c62 Compare January 8, 2025 22:13
@fanf
Copy link
Member Author

fanf commented Jan 8, 2025

PR updated with a new commit

1 similar comment
@fanf
Copy link
Member Author

fanf commented Jan 8, 2025

PR updated with a new commit

noReport: Option[Double],
reportsDisabled: Option[Double],
badPolicyMode: Option[Double]
)
Copy link
Member Author

Choose a reason for hiding this comment

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

moved in the end of the file, with other serialization things

@fanf
Copy link
Member Author

fanf commented Jan 8, 2025

PR updated with a new commit

1 similar comment
@fanf
Copy link
Member Author

fanf commented Jan 8, 2025

PR updated with a new commit

@fanf fanf force-pushed the arch_26046/migrate_compliance_status_from_lift_json_to_zio_json branch from 5271ae6 to 8124190 Compare January 8, 2025 22:39
Copy link
Contributor

@clarktsiory clarktsiory left a comment

Choose a reason for hiding this comment

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

LGTM, just some suggestions/questions

Comment on lines 645 to 646
.withFieldComputed(_.run, _._1.transformInto[ApiRunInfo])
.withFieldComputed(_.status, _._2.transformInto[ApiStatusInfo])
Copy link
Contributor

Choose a reason for hiding this comment

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

So now with the last chimney version, it could be :

Suggested change
.withFieldComputed(_.run, _._1.transformInto[ApiRunInfo])
.withFieldComputed(_.status, _._2.transformInto[ApiStatusInfo])
.withFieldRenamed(_._1, _.run)
.withFieldRenamed(_._1, _.status)

Copy link
Member Author

Choose a reason for hiding this comment

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

yep,it works now (with a 2 in second line)

Comment on lines 660 to 669
// here, I'm not sure that we want compliance or
// compliance percents. Having a normalized value
// seems far better for queries in the future.
// but in that case, we should also keep the total
// number of events to be able to rebuild raw data

// always map compliance field from ComplianceLevel to ComplianceSerializable automatically
implicit private lazy val transformComplianceLevel: Transformer[ComplianceLevel, ComplianceSerializable] = {
case c: ComplianceLevel => c.computePercent().transformInto[ComplianceSerializable]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

that seems like a transformation that should be reusable, is there a reason why it is here instead of in the ComplianceLevel companion object ?
In fact there already is a transformComplianceSerializable: Transformer[ComplianceLevel, ComplianceLevelSerialisation], I am not sure about the difference between ComplianceSerialization and ComplianceLevelSerialisation...

Copy link
Member Author

Choose a reason for hiding this comment

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

the existing one is for thing of the same type: ComplianceLevel is the number of things in each kind, and ComplianceLevelSerialisation the corresponding json.
This one is changing the type from level to percent. It's a local tool because almost all reports have the percent, so just removing boilerplate in the other transformers.

Comment on lines 582 to 587
/*
* This is the serialization for API.
* We are again redefining roughly the same objects.
*/
// not sure why it doesn't see that they are used
@nowarn("msg=private val .* in object NodeStatusReportSerialization is never used")
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer the solution of declaring everything in a private object InternalDatastructures, this avoids the issue of private implicits being reported as unused by the compiler.
Plus, in all the code below, there are really many things that end up being private, the structure and the dependencies are becoming hard to follow...

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@@ -49,6 +49,7 @@ import com.normation.rudder.domain.RudderDit
import com.normation.rudder.domain.RudderLDAPConstants.*
import com.normation.rudder.domain.policies.Tag
import com.normation.rudder.domain.policies.TagName
import com.normation.rudder.domain.policies.Tags as TAGS
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
Member Author

Choose a reason for hiding this comment

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

BECAUSE
(there is a name clash, and this one is used only one time)

@fanf fanf force-pushed the arch_26046/migrate_compliance_status_from_lift_json_to_zio_json branch from 8124190 to 8b1aab6 Compare January 9, 2025 21:14
@fanf fanf requested a review from clarktsiory January 9, 2025 21:15
@Normation-Quality-Assistant
Copy link
Contributor

OK, merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant merged commit 6cb85f1 into Normation:master Jan 10, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants