feat(reconciler): add GraphBuilder for recursive entity extraction#471
Merged
Conversation
Introduces GraphBuilder that recursively extracts nested entities from
protobuf messages and builds graph representations. Key features:
- Recursive entity extraction using reflection on proto messages
- Entity matching integration for deduplication via EntityMatcher
- Complete node data assembly with metadata and relationships
- Support for all NetBox entity types with proper edge relationships
Also refactors entitymatcher to use minimal Repository interface
following interface segregation principle, and applies idiomatic Go
improvements (any vs interface{}, require.NotNil for lint).
- Add strcase package with ToSnakeCase and ToUpperSnakeCase utilities
- Implement bidirectional edge relationships (BELONGS_TO/HAS)
- Use errors.Is(err, pgx.ErrNoRows) instead of string comparison
- Add error context wrapping for better debugging
- Replace interface{} with any in templates (Go 1.18+)
- Remove unused function parameters
- Use strings.Builder for string concatenation
- Pre-allocate slices with known capacity
- Fix test naming for empty string edge cases
|
Go test coverage
Total coverage: 55.4% |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70fa33abf1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Add canBeNil helper to check if reflect.Value supports nil checks - Skip scalar slice items (string, int) that would panic on IsNil - Handle protobuf oneof fields (reflect.Interface) when extracting edges - Unwrap interface values to process CableTermination and similar entities
- Add comprehensive tests for GraphBuilder functions - Add tests for generated entity_mappings.go functions - Improve reconciler package coverage from 38% to 57% - Cover edge type generation, entity creation, and node operations
Add assertion to verify the entity type matches expected value when the result is non-nil.
… functions Break up the 212-line processEntityRecursively function into smaller, single-responsibility functions: - findEntityMatch: confidence-based matching attempt - updateMatchedNode: handle matched node updates - maybeUpdateNodeSchema: lazy schema migration check - upsertMatchedNodeData: duplicate count handling - createEdgesForNode: edge extraction and creation The main function is now ~62 lines and delegates to focused helpers, improving readability and testability.
jajeffries
reviewed
Jan 26, 2026
jajeffries
reviewed
Jan 26, 2026
jajeffries
approved these changes
Jan 26, 2026
Contributor
jajeffries
left a comment
There was a problem hiding this comment.
Overall looks good, couple of minor comments, but happy for them to be tidied up later
- Move snakeToPascal from cmd/protograph/parser.go to strcase package as ToPascalCase for reusability - Improve ToSnakeCase to handle acronyms correctly: "IPAddress" -> "ip_address", "DeviceID" -> "device_id" - Simplify ToUpperSnakeCase to reuse ToSnakeCase
- NewGraphBuilder now delegates to NewGraphBuilderWithMatcher - Rename shadowed variable in extractEdgeProperties (fieldValue -> fv)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds GraphBuilder for recursive entity extraction with bidirectional edge relationships and confidence-based entity matching support. Some of methods/functions not used here yet, to be utilized in next PR.
Key Features
New Packages
🤖