-
Notifications
You must be signed in to change notification settings - Fork 21
Description
The Datadog plugin crashes with a segmentation violation when fetching cost data. The crash occurs in the getDDCostsForWindow function at line 237 of main.go.
Environment
- OpenCost Version: 1.42.0
- Plugin Version: v0.0.15
- Platform: linux/arm64
- Kubernetes: EKS (Amazon Elastic Kubernetes Service)
Stack Trace
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xaa7248]
goroutine 26 [running]:
main.(*DatadogCostSource).getDDCostsForWindow(0x40003cfb60, {0x4000792030?, 0x4000792048?}, 0x400032a4b0)
/home/runner/work/opencost-plugins/opencost-plugins/pkg/plugins/datadog/cmd/main/main.go:237 +0x318
main.(*DatadogCostSource).GetCustomCosts(0x40003cfb60, 0x4000698000)
/home/runner/work/opencost-plugins/opencost-plugins/pkg/plugins/datadog/cmd/main/main.go:83 +0x430
Root Cause Analysis
The crash occurs at line 237 in the pagination handling code:
if resp.Meta != nil && resp.Meta.Pagination != nil && resp.Meta.Pagination.NextRecordId.IsSet() {
nextPageId = *resp.Meta.Pagination.NextRecordId.Get() // <- CRASH HERE
}
The code assumes that if IsSet() returns true, then .Get() will return a non-nil pointer. However, the Datadog API client's optional value pattern can return nil even when "set".
Suggested Fix
if resp.Meta != nil && resp.Meta.Pagination != nil && resp.Meta.Pagination.NextRecordId.IsSet() {
if ptr := resp.Meta.Pagination.NextRecordId.Get(); ptr != nil {
nextPageId = *ptr
} else {
nextPageId = ""
}
} else {
nextPageId = ""
}
Steps to Reproduce
- Deploy OpenCost with Datadog plugin enabled
- Configure valid Datadog API and App keys
- Wait for the plugin to fetch cost data
- Observe SIGSEGV crash in logs