Skip to content

Additional query filters, parallel queries and changelog query added#4

Open
businessbean wants to merge 1 commit intomasterfrom
region-info
Open

Additional query filters, parallel queries and changelog query added#4
businessbean wants to merge 1 commit intomasterfrom
region-info

Conversation

@businessbean
Copy link
Copy Markdown
Contributor

@businessbean businessbean commented Feb 9, 2026

  • 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 to use the NetBox changelog. See the documentation for details and performance considerations
  • parallel_queries option added to speed up the check process by running multiple queries in parallel
  • golang version updated to 1.25.7

@businessbean businessbean marked this pull request as ready for review February 18, 2026 11:01
@businessbean businessbean force-pushed the region-info branch 4 times, most recently from 21b0989 to 6fa582d Compare February 24, 2026 17:19
@businessbean businessbean changed the title DeviceSite, DeviceRegion and DeviceTags properties added to the version output Additional query filters, parallel queries and changelog query added Feb 24, 2026
Copy link
Copy Markdown

@majewsky majewsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses several outdated idioms. Please check the suggestions generated by go fix ./... under Go 1.26.

@businessbean
Copy link
Copy Markdown
Contributor Author

This uses several outdated idioms. Please check the suggestions generated by go fix ./... under Go 1.26.

Hi Stefan, thanks for the hint. I will check that in a later change together with the update to 1.26.x

@majewsky
Copy link
Copy Markdown

If you are still on Go 1.25, you can do the same as golangci-lint run --enable modernize --fix. That is what was moved into the core toolchain as go fix in 1.26

- 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
Copy link
Copy Markdown

@majewsky majewsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working through my notification backlog, and finally got to this again.

Comment on lines +24 to +27
"token": "your-api-token",
"parallel_queries": 4,
"use_changelog": true,
"initial_lookback": "168h30m"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result, err := populateDeviceDetails(helper.DeviceName, input, currentDevice, nil, context.Background())
result, err := populateDeviceDetails(helper.DeviceName, input, currentDevice, nil, t.Context())

Comment on lines +37 to +39
lastUpdatedTime = device.LastUpdated.Get()
case netbox.Interface:
lastUpdatedTime = device.LastUpdated.Get()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +174 to +176
if configContextBytes, err := json.Marshal(configContextData); err == nil {
configContext = string(configContextBytes)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
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.

Comment on lines +91 to +94
if configured <= 0 {
return 1
}
return configured
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if configured <= 0 {
return 1
}
return configured
return max(configured, 1)

And then this can possibly be inlined.

Comment on lines +25 to +29
regions := make([]string, 0, len(regionSet))
for region := range regionSet {
regions = append(regions, region)
}
return regions
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
regions := make([]string, 0, len(regionSet))
for region := range regionSet {
regions = append(regions, region)
}
return regions
return slices.Collect(maps.Keys(regionSet))

Comment on lines +64 to +72
func getSiteRegion(siteId int32) string {
if siteRegionCache == nil {
return ""
}
if region, ok := siteRegionCache[siteId]; ok {
return region
}
return ""
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants