Additional query filters, parallel queries and changelog query added#4
Additional query filters, parallel queries and changelog query added#4businessbean wants to merge 1 commit intomasterfrom
Conversation
d3303fe to
cbcd2c8
Compare
21b0989 to
6fa582d
Compare
6fa582d to
d113305
Compare
Hi Stefan, thanks for the hint. I will check that in a later change together with the update to |
eb6968c to
374119a
Compare
|
If you are still on Go 1.25, you can do the same as |
374119a to
6961952
Compare
- region_name, tenant and tag properties added to the query filter - device_site, device_region and device_tags properties added to the version output - use_changelog option added - parallel_queries option added - initial_lookback parameter added - golang version updated to 1.25.7
6961952 to
67e8a33
Compare
majewsky
left a comment
There was a problem hiding this comment.
Working through my notification backlog, and finally got to this again.
| "token": "your-api-token", | ||
| "parallel_queries": 4, | ||
| "use_changelog": true, | ||
| "initial_lookback": "168h30m" |
There was a problem hiding this comment.
Indentation looks weird here. Probably a mix of tabs and spaces that displays inconsistently.
|
|
||
| currentDevice := *device | ||
| result, err := populateDeviceDetails(helper.DeviceName, input, currentDevice) | ||
| result, err := populateDeviceDetails(helper.DeviceName, input, currentDevice, nil, context.Background()) |
There was a problem hiding this comment.
| result, err := populateDeviceDetails(helper.DeviceName, input, currentDevice, nil, context.Background()) | |
| result, err := populateDeviceDetails(helper.DeviceName, input, currentDevice, nil, t.Context()) |
| lastUpdatedTime = device.LastUpdated.Get() | ||
| case netbox.Interface: | ||
| lastUpdatedTime = device.LastUpdated.Get() |
There was a problem hiding this comment.
This variable is not declared locally, so it writes into the global variable, which does not seem intentional. Either a local variable should be declared, or the non-error return values should be removed if the intent is to write directly into the global variables.
Same for referenceTime further below.
| if configContextBytes, err := json.Marshal(configContextData); err == nil { | ||
| configContext = string(configContextBytes) | ||
| } |
There was a problem hiding this comment.
In the err != nil case, the error is discarded silently. Either it should be handled explicitly in some way, or if a panic is fine, this can be shortened to
| if configContextBytes, err := json.Marshal(configContextData); err == nil { | |
| configContext = string(configContextBytes) | |
| } | |
| configContext = string(must.Return(json.Marshal(configContextData))) |
using https://pkg.go.dev/github.com/sapcc/go-bits/must#Return.
| if configured <= 0 { | ||
| return 1 | ||
| } | ||
| return configured |
There was a problem hiding this comment.
| if configured <= 0 { | |
| return 1 | |
| } | |
| return configured | |
| return max(configured, 1) |
And then this can possibly be inlined.
| regions := make([]string, 0, len(regionSet)) | ||
| for region := range regionSet { | ||
| regions = append(regions, region) | ||
| } | ||
| return regions |
There was a problem hiding this comment.
| regions := make([]string, 0, len(regionSet)) | |
| for region := range regionSet { | |
| regions = append(regions, region) | |
| } | |
| return regions | |
| return slices.Collect(maps.Keys(regionSet)) |
| func getSiteRegion(siteId int32) string { | ||
| if siteRegionCache == nil { | ||
| return "" | ||
| } | ||
| if region, ok := siteRegionCache[siteId]; ok { | ||
| return region | ||
| } | ||
| return "" | ||
| } |
There was a problem hiding this comment.
Delete this whole function and write only siteRegionCache[siteId] instead. A nil map behaves like an empty map during lookups, and a failed lookup defaults to the zero value.
region_name,tenantandtagproperties added to the query filterdevice_site,device_regionanddevice_tagsproperties added to the version outputuse_changelogoption added to use the NetBox changelog. See the documentation for details and performance considerationsparallel_queriesoption added to speed up the check process by running multiple queries in parallel1.25.7