-
Task
-
Resolution: Unresolved
-
Undefined
-
None
-
None
-
None
-
False
-
-
False
-
subs-swatch-thunder
-
-
Description
As a swatch developer, I need a single source of truth for cores/sockets normalization logic so that both swatch-tally and swatch-metrics-hbi services produce consistent values.
Currently, normalization logic is duplicated in:
- FactNormalizer (swatch-tally)
- MeasurementNormalizer (swatch-metrics-hbi)
- Product Usage Collectors (swatch-tally)
This leads to conflicting values between instance_measurements and host_tally_buckets tables.
Technical Details
Create new classes in swatch-common-instances/src/main/java/com/redhat/swatch/common/normalization/:
1. NormalizationContext.java - Input data class containing:
- rawCores / rawSockets
- coresPerSocket / threadsPerCore
- isMarketplace / cloudProvider
- isVirtual / isHypervisor / isUnmappedGuest
- arch / syspurposeUnits
- productIds
2. NormalizedMeasurements.java - Output data class containing:
- cores / sockets (normalized values)
3. CoreSocketNormalizer.java - Static method normalize(NormalizationContext ctx):
- Apply all normalization rules in priority order
- Return NormalizedMeasurements
Normalization Rules (Priority Order)
| Priority | Rule | Condition | Action |
|---|---|---|---|
| 1 | Marketplace | isMarketplace == true | cores=0, sockets=0 |
| 2 | Cloud Provider | cloudProvider != null | sockets=1 |
| 3 | Unmapped Guest | isVirtual && isUnmappedGuest && isRHEL | sockets=1 |
| 4 | Modulo-2 Rounding | (!isVirtual || isHypervisor) && sockets % 2 == 1 | sockets++ |
| 5 | vCPU Calculation | arch=="x86_64" && isVirtual | cores = cores / threadsPerCore |
| 6 | Unit-Based | units == "Sockets" | cores=null |
| 6 | Unit-Based | units == "Cores/vCPU" | sockets=null |
| 7 | Null Handling | cores == null | cores = fallback |
Acceptance Criteria
- NormalizationContext class created with all required fields
- NormalizedMeasurements class created
- CoreSocketNormalizer.normalize() method implements all rules in priority order
- Comprehensive unit tests for each normalization rule
- Edge case tests (null inputs, boundary values)
- Tests match existing behavior in FactNormalizer and MeasurementNormalizer
- blocks
-
SWATCH-4319 Migrate swatch-tally FactNormalizer to use CoreSocketNormalizer
-
- New
-
-
SWATCH-4320 Migrate swatch-metrics-hbi MeasurementNormalizer to use CoreSocketNormalizer
-
- New
-
- relates to
-
SWATCH-4319 Migrate swatch-tally FactNormalizer to use CoreSocketNormalizer
-
- New
-
-
SWATCH-4320 Migrate swatch-metrics-hbi MeasurementNormalizer to use CoreSocketNormalizer
-
- New
-
-
SWATCH-4321 Simplify Product Usage Collectors to remove re-normalization
-
- New
-