Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ScrapeClass TLSConfig nil pointer exception #6507

Merged
merged 2 commits into from Apr 15, 2024

Conversation

kakkoyun
Copy link
Member

Signed-off-by: Kemal Akkoyun kakkoyun@gmail.com

Description

When only relabeling is configured in a ScrapeClass object, the TLSConfig field is nil. This causes a panic when the TLSConfig field is accessed in the ScrapeClass object.

I'm not sure about the business logic of the ScrapeClass TLSConfig field, but from pure Go perspective, it should fix the panic.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x1ad78e1]

goroutine 386 [running]:
github.com/prometheus-operator/prometheus-operator/pkg/prometheus.(*ConfigGenerator).MergeTLSConfigWithScrapeClass(0x20d7080?, 0xc00172b420, 0xc000fe6d08?)
        /home/runner/work/prometheus-operator/prometheus-operator/pkg/prometheus/promcfg.go:417 +0x81
github.com/prometheus-operator/prometheus-operator/pkg/prometheus.(*ConfigGenerator).generateServiceMonitorConfig(_, _, {{0xc000a7c250, 0x5}, 0x0, {0xc000a7c128, 0x8}, {0xc000a7c255, 0x5}, 0x0, ...}, ...)
        /home/runner/work/prometheus-operator/prometheus-operator/pkg/prometheus/promcfg.go:1370 +0xd3d
github.com/prometheus-operator/prometheus-operator/pkg/prometheus.(*ConfigGenerator).appendServiceMonitorConfigs(0xc000c5a6c0, {0x0, 0x0, 0x0}, 0xc0014ae420, 0x0, 0xc000b4d500, 0x1)
        /home/runner/work/prometheus-operator/prometheus-operator/pkg/prometheus/promcfg.go:2298 +0x3e5
github.com/prometheus-operator/prometheus-operator/pkg/prometheus.(*ConfigGenerator).GenerateServerConfiguration(0xc000c5a6c0, {0x27b2620, 0xc00098b540}, {0xc000e372fd, 0x3}, {0x0, 0x0}, _, _, {{0x0, ...}}, ...)
        /home/runner/work/prometheus-operator/prometheus-operator/pkg/prometheus/promcfg.go:672 +0x3f5
github.com/prometheus-operator/prometheus-operator/pkg/prometheus/server.(*Operator).createOrUpdateConfigurationSecret(0xc000173688, {0x27b2620, 0xc00098b540}, 0xc0010aa308, 0xc000c5a6c0, {0xc001adc830, 0x1, 0x1}, 0xc000b4d500)
        /home/runner/work/prometheus-operator/prometheus-operator/pkg/prometheus/server/operator.go:1152 +0xa68
github.com/prometheus-operator/prometheus-operator/pkg/prometheus/server.(*Operator).sync(0xc000173688, {0x27b2620, 0xc00098b540}, {0xc00148a060, 0xe})
        /home/runner/work/prometheus-operator/prometheus-operator/pkg/prometheus/server/operator.go:778 +0x8c5
github.com/prometheus-operator/prometheus-operator/pkg/prometheus/server.(*Operator).Sync(0xc000173688, {0x27b2620?, 0xc00098b540?}, {0xc00148a060, 0xe})
        /home/runner/work/prometheus-operator/prometheus-operator/pkg/prometheus/server/operator.go:725 +0x2c
github.com/prometheus-operator/prometheus-operator/pkg/operator.(*ResourceReconciler).processNextReconcileItem(0xc000066600, {0x27b2620, 0xc00098b540})
        /home/runner/work/prometheus-operator/prometheus-operator/pkg/operator/resource_reconciler.go:449 +0x231
github.com/prometheus-operator/prometheus-operator/pkg/operator.(*ResourceReconciler).Run.func1()
        /home/runner/work/prometheus-operator/prometheus-operator/pkg/operator/resource_reconciler.go:412 +0x3f
golang.org/x/sync/errgroup.(*Group).Go.func1()
        /home/runner/go/pkg/mod/golang.org/x/sync@v0.6.0/errgroup/errgroup.go:78 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 497
        /home/runner/go/pkg/mod/golang.org/x/sync@v0.6.0/errgroup/errgroup.go:75 +0x96

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Verification

Please check the Prometheus-Operator testing guidelines for recommendations about automated tests.

Example config to reproduce the issue:

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  name: k8s
spec:
  scrapeClasses:
    - name: base-scrape-class
      default: true
      relabelings:
        - targetLabel: cluster
          replacement: my-awesome-cluster
      # tlsConfig: {} # This would work.

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

[BUGFIX] Fix ScrapeClass TLSConfig nil pointer panic when only relabeling is configured.

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
@kakkoyun kakkoyun requested a review from a team as a code owner April 13, 2024 17:18
@xiu
Copy link
Contributor

xiu commented Apr 14, 2024

It looks good to me but I'd rather leave the approval to @nicolastakashi to check the logic.

Can we maybe add a test for this case in TestMergeTLSConfigWithScrapeClass?

@kakkoyun
Copy link
Member Author

Can we maybe add a test for this case in TestMergeTLSConfigWithScrapeClass?

Good point. I'll ad it.

Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

I agree that tests would be good to have :)

pkg/prometheus/promcfg.go Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/M and removed size/S labels Apr 15, 2024
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

👍
@kakkoyun merge it at your will :)

@kakkoyun
Copy link
Member Author

There's no merge button for me 😱 Could one of you please merge it?

@xiu xiu merged commit c15b12a into prometheus-operator:main Apr 15, 2024
17 checks passed
@kakkoyun kakkoyun deleted the fix_nil_ptr_exception branch April 16, 2024 12:17
@kakkoyun
Copy link
Member Author

@simonpasquier Maybe I should have merged this to the release branch?

@simonpasquier
Copy link
Contributor

@kakkoyun right it would be better to have the fix now rather than in a month. If you're motivated, you can cherry-pick the commit to the release-0.73 branch and push another PR.
cc @slashpai who's the current release shepherd :)

@slashpai
Copy link
Contributor

@kakkoyun Since its already merged can you cherry-pick and create the PR to release branch?

@kakkoyun
Copy link
Member Author

Thanks. I'll do it.

simonpasquier pushed a commit to simonpasquier/prometheus-operator that referenced this pull request Apr 18, 2024
simonpasquier added a commit that referenced this pull request Apr 18, 2024
fix: ScrapeClass TLSConfig nil pointer exception (#6507)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants