Auto-populate dynamic service-info timestamps#56
Auto-populate dynamic service-info timestamps#56AaryanCode69 wants to merge 1 commit intoelixir-cloud-aai:devfrom
Conversation
Reviewer's GuideMakes service-info timestamps optional in config and auto-populates them at startup while ignoring dynamic timestamp differences when deciding whether to reuse existing service-info. Sequence diagram for auto-populating service-info timestamps from configsequenceDiagram
participant AppStartup
participant RegisterServiceInfo
participant DB as ServiceInfoCollection
AppStartup->>RegisterServiceInfo: set_service_info_from_config()
RegisterServiceInfo->>DB: get_service_info()
alt service-info exists
DB-->>RegisterServiceInfo: db_info
else service-info not found
DB-->>RegisterServiceInfo: NotFound exception
RegisterServiceInfo->>RegisterServiceInfo: db_info = {}
end
RegisterServiceInfo->>RegisterServiceInfo: service_info = _get_service_info_from_config(db_info or None)
RegisterServiceInfo->>RegisterServiceInfo: ignored_fields = _dynamic_timestamp_fields()
RegisterServiceInfo->>RegisterServiceInfo: db_core = _without_fields(db_info, ignored_fields)
RegisterServiceInfo->>RegisterServiceInfo: service_core = _without_fields(service_info, ignored_fields)
alt db_core == service_core and _has_fields(db_info, ignored_fields)
RegisterServiceInfo-->>AppStartup: log Using available service info
else
RegisterServiceInfo->>DB: _upsert_service_info(service_info)
DB-->>RegisterServiceInfo: upsert ok
RegisterServiceInfo-->>AppStartup: log Service info registered
end
Class diagram for updated service-info config and controllerclassDiagram
class RegisterServiceInfo {
- registry_conf
- foca_conf
- host_name
- external_port
- api_path
- conf_info
- collection
+ __init__() void
+ set_service_info_from_config() void
+ set_service_info_from_app_context(headers Dict) None
- _get_service_info_from_config(db_info Dict) Dict
- _current_timestamp() str
- _dynamic_timestamp_fields() FrozenSet~str~
- _has_fields(data Dict, fields FrozenSet~str~) bool
- _without_fields(data Dict, fields FrozenSet~str~) Dict
- _upsert_service_info(data Dict) None
- get_service_info() Dict
- _get_headers() Dict
}
class ServiceInfoConfig {
+ id str
+ name str
+ type str
+ description str
+ organization OrganizationConfig
+ contactUrl str
+ documentationUrl str
+ createdAt Optional~str~
+ updatedAt Optional~str~
+ environment str
+ version str
}
class OrganizationConfig {
+ name str
+ url str
}
class TIMESTAMP_FIELDS {
+ createdAt
+ updatedAt
}
RegisterServiceInfo --> ServiceInfoConfig : uses
ServiceInfoConfig --> OrganizationConfig : has
RegisterServiceInfo --> TIMESTAMP_FIELDS : reads
Flow diagram for deciding whether to reuse or update service-infoflowchart TD
A[Start: set_service_info_from_config] --> B[Fetch existing db_info]
B --> C{db_info found?}
C -- No --> D[Set db_info to empty dict]
C -- Yes --> E[Use returned db_info]
D --> F[Build service_info from config and timestamps]
E --> F
F --> G[Determine ignored_fields using _dynamic_timestamp_fields]
G --> H[Compute db_core = db_info without ignored_fields]
H --> I[Compute service_core = service_info without ignored_fields]
I --> J{db_core equals service_core
and db_info has all ignored_fields?}
J -- Yes --> K[Log Using available service info]
K --> L[End]
J -- No --> M[Upsert service_info into database]
M --> N[Log Service info registered]
N --> L[End]
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The logic in
set_service_info_from_configfor comparingdb_infoandservice_infowhile special-casing timestamp fields is fairly dense; consider extracting the comparison into a named helper with a short docstring to make the intent and conditions easier to follow. - In
_has_fields, you’re checking field presence via truthiness (data.get(field)), which will treat empty strings or other falsy-but-present values as missing; if that’s not intentional, consider usingfield in datainstead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The logic in `set_service_info_from_config` for comparing `db_info` and `service_info` while special-casing timestamp fields is fairly dense; consider extracting the comparison into a named helper with a short docstring to make the intent and conditions easier to follow.
- In `_has_fields`, you’re checking field presence via truthiness (`data.get(field)`), which will treat empty strings or other falsy-but-present values as missing; if that’s not intentional, consider using `field in data` instead.
## Individual Comments
### Comment 1
<location path="cloud_registry/service_models/custom_config.py" line_range="194-197" />
<code_context>
organization: OrganizationConfig
contactUrl: str
documentationUrl: str
- createdAt: str
- updatedAt: str
+ createdAt: Optional[str] = None
+ updatedAt: Optional[str] = None
environment: str
version: str
</code_context>
<issue_to_address>
**question (bug_risk):** Making createdAt/updatedAt optional may allow silently missing timestamps if validation elsewhere doesn’t enforce them.
This change makes the model dependent on `RegisterServiceInfo` (or similar logic) to always set these fields. If any code path constructs and persists `ServiceInfoConfig` directly (e.g., other services, utilities, or migrations), it could save documents without timestamps. Please verify that all persistence paths either run through the auto-timestamp logic or explicitly set these values.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| createdAt: str | ||
| updatedAt: str | ||
| createdAt: Optional[str] = None | ||
| updatedAt: Optional[str] = None | ||
| environment: str | ||
| version: str |
There was a problem hiding this comment.
question (bug_risk): Making createdAt/updatedAt optional may allow silently missing timestamps if validation elsewhere doesn’t enforce them.
This change makes the model dependent on RegisterServiceInfo (or similar logic) to always set these fields. If any code path constructs and persists ServiceInfoConfig directly (e.g., other services, utilities, or migrations), it could save documents without timestamps. Please verify that all persistence paths either run through the auto-timestamp logic or explicitly set these values.
Description
This change removes the hardcoded
createdAtandupdatedAtvalues from the defaultservice-infoconfiguration and makes them optional in the custom config model. The registry now auto-populates those timestamps when seedingservice-infofrom configuration, while still preserving explicitly provided values if they exist.This keeps the startup-generated
service-infometadata current without requiring manual timestamp updates inconfig.yaml.Dependencies required for this change: none.
Fixes #30
Type of change
Please delete options that are not relevant.
Checklist:
Summary by Sourcery
Auto-manage service-info timestamps from configuration while keeping existing values when explicitly provided.
Bug Fixes:
Enhancements: