Skip to content

[BUG] Datadog plugin crashes with SIGSEGV in getDDCostsForWindow - nil pointer dereference #68

Description

@ermeaney

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

  1. Deploy OpenCost with Datadog plugin enabled
  2. Configure valid Datadog API and App keys
  3. Wait for the plugin to fetch cost data
  4. Observe SIGSEGV crash in logs

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions