owned this note
owned this note
Published
Linked with GitHub
# Pulp3-pulp_rpm Applicability Design
## Executive Summary
In the RPM World, a key question Pulp needs to answer is “Given a set of installed Packages, what updates are **applicable** to me?”. ‘Applicable’ implies that we know three pieces of information:
* A list of Package NEVRAs
* A list of repositories we care about
* A definition of module-state (installed/enabled modules)
And can return the following information:
* A list of all Package NEVRAs, available in the specified repositories, which are updates to the specified incoming list of NEVRAs (**required**)
* A list of Advisories under which those Packages were released (**required**)
* A list of Module NSVCAs, available in the specified repositories, which are updates to the specified incoming list of enabled NSVCAs (**required**)
* A list of CVEs associated with those Advisories (**optional/stretch**)
All of the required fields may return null-lists - Packages and Modules if there are no updates available, Advisories in that case and in the case where Packages are not associated with Advisories.
CVEs are an optional stretch goal - we do not currently have any requests for applicability to return CVE data, but it is available in the database.
Pulp_rpm in Pulp3 needs to be able to answer this question as quickly as possible. This doc is intended to capture the requirements, planning, and design options for answering this question.
## Definitions
The pulp_rpm entities that applicability is concerned with include:
* **Package** : binary blobs that are installed on/into systems/containers
* **NEVRA** : Name/epoch/version/release/architecture - unique(ish) identifier of an Package (e.g., different signing-key or different checksum, for same NEVRA, pulled into a single repository, has happened ‘in the wild’ in the past)
* **Repository** : Holder of Packages and metadata
* **Advisory** (aka **Erratum**) : Atomic unit of repository-update and update-metadata
* **CVE** : Common Vulnerabilities and Exposures - public definition of security issues. Associated with Advisories
* **Module** : a set of packages that define an entity with its own release-cycle (separate from the base-OS on which it is installed) - e.g., Postgresql might be a module
* **Module-stream** : a major release of a specific module - e.g., postgresql-10 and postgresql-11 might be separate streams of the postgresql module
* **Module-context** : the ‘base-OS’ release the module is built for.
* **NSVCA** - Name/Stream/Version/Context/Architecture - unique identifier of a specific installed/enabled module
## Current Pulp2 State
* Pulp2 data-store is MongoDB
* Pulp2 maintains a list of **Consumers**.
* A consumer ‘knows’ the following ‘**content-state**’:
* Its installed list of Packages
* Its enabled repositories
* Its current modularity-state
* Because Pulp2 maintains the consumers, it can **cache** applicability-state
* Because consumers change, Pulp2 must be informed whenever a given consumer’s content-state changes, and must recalculate and update that consumer’s applicability-state.
* Because the content of repositories can change, Pulp2 must be informed whenever a repository’s state changes, and must recalculate and update the applicability-state of all consumers subscribed to that repository.
* Pulp2 can be queried for the applicability-state of a specified consumer or set of consumers, reading from the consumer’s applicability cache.
* Pulp2 returns a dictionary of lists, keyed by CONTENT TYPE, as applicability-state.
## Pulp3 differences
* Pulp3 uses Postgres to maintain the relationships between entities
* Pulp3 **DOES NOT** maintain consumers
* Therefore, content-state **MUST BE PROVIDED** in each call to applicability
* Therefore, Pulp3’s applicability-calculation is **STATELESS**
* Therefore, Pulp3 **DOES NOT REQUIRE** the applicability-recalculation infrastructure
* Therefore, performance is a **HIGH PRIORITY** for Pulp3’s ability to calculate and return applicability-state
## Requirements
* Supports all RPM distributions
* RHEL
* Fedora
* CentOS
* SUSE
* Stateless
* Fast
* Input **must** include:
* Package NEVRA list
* a list of repositories-of-interest
* module-install/enabled-info
* Output **must** include list of updateable Package NEVRAs.
* Output **must** include list of updateable Module NSVCAs.
* Output **may** include applicable-advisories
* Some secondary requirements - subject to change
* Avoid undue complication at install time
* Avoid undue complications with monitoring
* Avoid undue bloating of hardware requirements for Pulp3
* Include CVEs associated with advisories (very optional)
## Approach
There are a number of projects/products other than Pulp-2 at Red Hat that calculate applicability based on content-state in a data store, including (but possibly not limited to) [Pulp-2](https://github.com/pulp/pulp_rpm/tree/2-master), [spacewalk](https://github.com/spacewalkproject/spacewalk), and [VMAAS](https://github.com/RedHatInsights/vmaas). As a first cut, we are going to try to reuse code from the most recent attempt, VMAAS. That service has been in production, is the backend ‘definition of truth’ for applicability in the Vulnerability portion of cloud.redhat.com, and has had some significant performance work done at the database level that we hope to be able to take advantage of. Also, unlike all the other current codebases, VMAAS shares the “stateless” and “knows nothing about consumers of applicability” design goals.
Our overarching goals are threefold, in order:
1. “Have a solid API defined ASAP”
1. “Have that API working ASAP (even if performance is suboptimal)”
1. “Address performance issues by evaluating behavior under actual data loads”.
The general approach we will be taking is
1. Propose initial API
1. Collaborate with community to refine and solidify
1. Implement API handlers as stubs
a. API validation implemented
b. Canned response returned
1. Implement/reuse ‘version compare’ in Postgresql using current NEVRA data of pulp_rpm as of 3.0’s release
1. Implement test-cases for testing correctness
1. Measure performance-characteristics under larger data-loads and adjust/add-to how we store NEVRA information in response
Many of these points can be worked on concurrently.
## API - [Let the Fun Begin!]
### Overview IN:
* List of NEVRAs (required)
* List of repositories (required)
* Set of modularity information (can be empty)
### Overview OUT:
Nested JSON structure that contains:
* For each repository:
* For each incoming NEVRA found in that repository:
* For each possible update to that NEVRA in that repository:
* Update NEVRA
* Advisory that released that update (if any)
We choose to categorize output by-repository because the point of applicability is knowing what needs to be updated, and where the updates are available. “Firefox is out of date” is nice, “firefox as delivered from your ‘third-party-apps-x86_64’ repository is out of date” makes it possible for the user to take the next step.
### Specific Use Cases
1. As a user, I can get **all the applicability information** known to pulp_rpm for a set of NEVRAs and repositories
* URL: POST http://pulp.example.com/pulp/api/v3/rpm/applicability
* IN JSON:
```
{ ‘rpms’: [‘nevra1’, ..., ’nevraN’],
‘repositories’: [‘repo-version-id1’,..., repo-version-idN’],
‘modules’: [
{‘module_nsvca’: ‘mod1’, ‘module_state’: ‘enabled’},
{‘module_nsvca’: ‘mod2’, ‘module_state’: ‘disabled’},
...
]
}
```
* OUT JSON:
```
{ ‘repositories’ :
[
{ ‘repo-version-id’: ‘repo-version-id1’,
‘requested_packages’ : [
{ ‘package’ : ‘nevra1’,
‘updates’ : [
{ ‘nevra’ : ‘nevra1.1’, ‘cause’ : ‘advisory-1’ },
{ ‘nevra’ : ‘nevra1.2’, ‘cause’ : ‘advisory-2’ },
...
{ ‘nevra’ : ‘nevra1.N’, ‘cause’ : None }
]
},
{ ‘package’ : ‘nevra2’,
‘updates’ : [
{ ‘nevra’ : ‘nevra2.1’, ‘cause’ : ‘advisory-3’ },
{ ‘nevra’ : ‘nevra2.2’, ‘cause’ : ‘advisory-4’ },
...
{ ‘nevra’ : ‘nevra1.N’, ‘cause’ : None }
]
},
...
],
‘requested_modules’ : [
{ ‘module’ : ‘nsvca-1’,
‘updates’ : [
{ ‘nsvca’ : ‘nsvca1.1’, ‘cause’ : ‘advisory-10’ },
{ ‘module’ : ‘nsvca1.2’, ‘cause’ : None },
...
{ ‘nsvca’ : ‘nsvca1.N’, ‘cause’ : ‘advisory-N’ },
]
},
{ ‘module’ : ‘nsvca-2’,
‘updates’ : [
{ ‘nsvca’ : ‘nsvca2.1’, ‘cause’ : ‘advisory-20’ },
{ ‘nsvca’ : ‘nsvca2.2’, ‘cause’ : None },
...
{ ‘nsvca’ : ‘nsvca2.N’, ‘cause’ : ‘advisory-M’ },
]
},
...
]
},
{ ‘repo-version-id’ : ‘repo-version-id2’, … },
…
{ ‘repo-version-id’ : ‘repo-version-idN’, … }
]
}
```
2. As a user, I can get **just the set of uninstalled advisories** for a set of NEVRAs and repositories
* URL: POST http://pulp.example.com/pulp/api/v3/rpm/applicability/advisories
* IN JSON: see #1
* OUT JSON:
```
{ ‘repositories’ :
[
{ ‘repo-version-id’: ‘repo-version-id1’, ‘applicable_advisories’ : [ ‘advisory-1’, …, ‘advisory-N’] },
…,
{ ‘repo-version-id’: ‘repo-version-idN’, ‘applicable_advisories’ : [ ‘advisory-1’, …, ‘advisory-N’] }
]
}
```
3. As a user, I can get **just the number of Packages that can be updated** from a set of NEVRAs and repos
Collapse #3 and #4 into one? See below.
4. As a user, I can get **just the number of uninstalled advisories** for…
* URL:POST http://pulp.example.com/pulp/api/v3/rpm/applicability/overview
* IN JSON: see #1
* OUT JSON:
```
{ ‘repositories’ :
[
{ ‘repo-version-id’: ‘repo-version-id1’,
‘num_applicable_packages’ : P,
‘num_applicable_modules’ : M,
‘num_applicable_advisories’ : A
},
…,
{ ‘repo-version-id’: ‘repo-version-idN’,
‘num_applicable_packages’ : P,
‘num_applicable_modules’ : M,
‘num_applicable_advisories’ : A
},
]
}
```
Number 1 is the base requirement. The rest are suggestions for potentially-useful shortcuts, based on how applicability is used in other products (primarily Satellite and Vulnerability)
### References for comparison
* [Pulp2 API](https://docs.pulpproject.org/en/2.21/dev-guide/integration/rest-api/consumer/applicability.html#query-content-applicability)
* [VMAAS API](https://webapp-vmaas-stable.1b13.insights.openshiftapps.com/api/ui/)
## Plan
* Design approach out to community before break (this doc)
* Minimal Viable Product by end of January-2020
* Addresses katello’s use-case(s)
* API is solid
* Performance will be whatever it is (naive approach)
* Post-MVP plans will be driven by:
* Community response to additional API needs
* Performance under large data loads (10K repos, 250K Packages, 1K NEVRAs - response in 250msec? (wild guess here) (would mean “recalc all 10K of my systems”, from outside, would take 45 min?)
## Testing
Applicability testing can be fraught with peril and edge-cases. Correctness-testing needs a defined repository with
* At least two Packages with no update
* At least two Packages with one update
* At least two Packages with three updates
* At least two modules with no updates
* At least one module with updates
The correct-output for the fixture should be determined ‘by hand’ and written into a correctness-file associated with the test-suite. Tests against the known-quantity can then compare directly against the canonical-definition-of-correct data.
This known-quantity needs to be available ASAP - ‘correctness’ is The Hard Part of applicability, and we will want to be able to test it from the very beginning.
## Alternatives
One alternative we discussed was whether we could just stand up the VMAAS ‘webapp’ service and use its approach. The short answer is “we could”, with something along these lines [drawing needed] :
* Webapp stood up in its own container
* Teach pulp_rpm to export all its data in webapp-expected format, to that container
* Intercept applicability-api-calls, transform to webapp-expected format, gather results
* Return results in form desired for Pulp
The combination of install/management/monitoring complexity, and memory-impact (webapp in production keeps ~5Gb+ resident in memory at all times) made us decide against this approach. It would certainly be the way to guarantee fastest-possible-performance, however. If we discover performance-at-scale becoming a significant issue, we could go down this path without affecting the exposed API.
## Exposures
* Advisory-to-Package not currently modeled in the DB for Pulp3.
* Modularity. Computing availability in the face of modularity has turned out to be more exciting than anyone wanted it to be. In addition, there are known problems/errors/ambiguities in modularity, and the canonical definition of ‘correct’ continues to be ‘whatever libdnf is implementing this week’. We are likely to be affected by the complexity (and uncertainty) here.
* Edge cases. Not just those introduced by modularity, either. NEVRA ‘is newer than’ has a number of ways to go subtly wrong. At a minimum, this code needs to be wrong **in the same way as everything else** in the RPM ecosystem. Consistency is king.
* Fedora and CentOS - make sure everything works for pre- and post-modularity versions.
* SUSE. As for CentOS and Fedora, will probably be most impactful of testing. Current installation guidelines explicitly say “requires some dependencies such as libsolv and libmodulemd which is provided only by Red Hat family distributions like Fedora.” This is needed for dependency-resolution, not applicability - but to what degree is Pulp3 suporting SUSE in the short term?
## References
[Pulp2 Applicability-query API](https://docs.pulpproject.org/en/2.21/dev-guide/integration/rest-api/consumer/applicability.html#query-content-applicability)
[VMAAS improved-EVR_T](https://github.com/RedHatInsights/vmaas/blob/master/database/vmaas_db_postgresql.sql#L2)