lazy loading customs now#910
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds optional “lazy loading” of Kentik device custom columns so custom-column data can be fetched on-demand (rather than always during initial device listing), and threads context.Context through device lookup calls.
Changes:
- Track whether a device’s custom columns have been loaded via a new
Device.loadedCustomsflag andLoadedCustoms()accessor. - Add
KT_API_LAZY_LOAD_CUSTOMSconfiguration and updateKentikApi.GetDeviceto optionally load custom columns on first access. - Update JCHF flow enrichment to call
GetDevicewith a context.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/kt/device_types.go | Tracks whether custom columns were loaded for a Device. |
| pkg/cat/jchf.go | Updates device lookups to pass context.Context. |
| pkg/api/api.go | Adds lazy-load toggle and on-demand custom-column fetching in GetDevice. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+251
to
+269
| if api.lazyLoadCustoms && !dev.LoadedCustoms() { | ||
| api.mux.Lock() | ||
| defer api.mux.Unlock() | ||
| if dev.LoadedCustoms() { | ||
| return dev | ||
| } | ||
| for _, info := range api.config.KentikCreds { | ||
| md := metadata.New(map[string]string{ | ||
| "X-CH-Auth-Email": info.APIEmail, | ||
| "X-CH-Auth-API-Token": info.APIToken, | ||
| }) | ||
| ctxo := metadata.NewOutgoingContext(ctx, md) | ||
| err := api.loadCustoms(ctxo, dev.IDStr, dev) | ||
| if err != nil { | ||
| api.Warnf("Cannot load customs for %s %s, %v", dev.IDStr, info.APIEmail, err) | ||
| } | ||
| break | ||
| } | ||
| } |
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.
No description provided.