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

Custom queries #3720

Merged
merged 1 commit into from
Sep 19, 2023
Merged

Custom queries #3720

merged 1 commit into from
Sep 19, 2023

Conversation

dsessler7
Copy link
Contributor

@dsessler7 dsessler7 commented Sep 13, 2023

Checklist:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • New feature
  • Bug fix
  • Documentation
  • Testing enhancement
  • Other

What is the current behavior (link to any open issues here)?
Currently, the only way that users can provide custom queries to the exporter is by providing a file that will be used instead of the default queries file. This means that if the user wants to keep the defaults, they have to copy the default queries into the custom queries file they provide.

What is the new behavior (if this is a feature change)?

  • Breaking change (fix or feature that would cause existing functionality to change)
    This PR introduces the ability to simply append custom queries to the existing default queries. This ability is feature gated, so it is not a breaking change.

Other Information:

internal/controller/postgrescluster/pgmonitor.go Outdated Show resolved Hide resolved
internal/controller/postgrescluster/pgmonitor.go Outdated Show resolved Hide resolved
@jmckulk jmckulk self-requested a review September 18, 2023 18:16
@dsessler7 dsessler7 marked this pull request as ready for review September 18, 2023 19:04
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
internal/controller/postgrescluster/pgmonitor.go Outdated Show resolved Hide resolved
testing/kuttl/e2e/exporter/03--check-queries.yaml Outdated Show resolved Hide resolved
testing/kuttl/e2e/exporter/03--check-queries.yaml Outdated Show resolved Hide resolved
internal/controller/postgrescluster/pgmonitor.go Outdated Show resolved Hide resolved
@jmckulk jmckulk self-requested a review September 18, 2023 21:08
Makefile Outdated
@@ -187,7 +187,7 @@ build-postgres-operator-image: build/postgres-operator/Dockerfile
##@ Test
.PHONY: check
check: ## Run basic go tests with coverage output
$(GO_TEST) -cover ./...
QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" $(GO_TEST) -cover ./...
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 is there a way you can write the go tests so that you don't need access to the queries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... So I added this because one of the tests was failing without it, but I'm realizing that this test was being run as a unit test, but it's really an integration test. So, I'm thinking I should just add the following to the top of the exporter_test.go file:

//go:build envtest
// +build envtest

Copy link
Collaborator

Choose a reason for hiding this comment

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

📝 we don't have to provide build tags in both of these syntaxes. Since go1.18, go:build is the new, preferred syntax and +build can be able to be removed.

I see that we have them in a bunch of places still - maybe it's worth a story to remove them

},
},
}
configVolume.VolumeSource.Projected.Sources = append(configVolume.VolumeSource.Projected.Sources,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let me just talk this out:
lines 301-310: we always have a configVolume that projects a volume from cluster.Spec.Monitoring.PGMonitor.Exporter.Configuration -- which might be nil, right? (And we've had this code for 2 years now.)

Now, lines 318-329:

  • if you have the feature gate turned off & have provided no custom configuration, we add the default queries configmap to that projected volume -- the cluster now has both volumesources, but only default queries
  • if you have the feature gate turned on & have provided no custom configuration, we add the default queries configmap to that projected volume -- the cluster now has both volumesources, but only default queries
  • if you have the feature gate turned off & have provided custom configuration, we DON'T add the default queries configmap to that projected volume -- the cluster now has only custom queries (and one volumesource)
  • if you have the feature gate turned on & have provided custom configuration, we add the default queries configmap to that projected volume -- the cluster now has both custom & default queries

OK, just wanted to type that out.

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 makes me wonder if we should be adding the empty volumeSources?

Copy link
Contributor

Choose a reason for hiding this comment

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

We've been doing it for ~2 years, so I guess it's ok, but I don't love it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, if it's not too difficult, I think we should stop doing that. Are there downsides? Would it be possible for someone to get into a situation where we added no volumeSources?

Maybe add a backlog issue and we can plan this

Copy link
Collaborator

@jmckulk jmckulk left a comment

Choose a reason for hiding this comment

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

lgtm

…exporter queries. This ability is feature gated with the AppendCustomQueries flag. The exporter kuttl tests have been adjusted. Tests that need the feature gate turned on have been added to e2e-other. This commit also moves some things from the postgrescluster package to the pgmonitor package.
@dsessler7 dsessler7 merged commit 714caba into CrunchyData:master Sep 19, 2023
10 of 15 checks passed
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.

3 participants