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

Add separate a module for the api package. #1856

Merged
merged 7 commits into from
Feb 19, 2025

Conversation

boris-smidt-klarrio
Copy link
Contributor

@boris-smidt-klarrio boris-smidt-klarrio commented Feb 11, 2025

No description provided.

api/go.mod Outdated
Comment on lines 8 to 10
github.com/onsi/ginkgo/v2 v2.22.2
github.com/onsi/gomega v1.36.2
github.com/openshift/api v0.0.0-20250207102212-9e59a77ed2e0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suspect that these dependencies add a lot of extra packages to the module.
So there are still many extra dependencies included.
The reduction is from 92 packages to 67 packages.

Copy link
Member

Choose a reason for hiding this comment

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

Does this fix the original issue of version incompatibility though?
The only reason we include the openshift api here is to allow route overrides here: https://github.com/grafana/grafana-operator/blob/master/api/v1beta1/typeoverrides.go#L331

So if you really want to get rid of the openshift dependency here, we can pull up the imported fields

Copy link
Contributor Author

@boris-smidt-klarrio boris-smidt-klarrio Feb 13, 2025

Choose a reason for hiding this comment

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

I've vendored the openshift api now.
In the release notes it should be noted that to remove the openapi package we had to make a breaking change to the imported api.
But not in the kubernetes api itself.

@boris-smidt-klarrio boris-smidt-klarrio changed the title Add separate package for the api package. Add separate module for the api package. Feb 13, 2025
@boris-smidt-klarrio boris-smidt-klarrio changed the title Add separate module for the api package. Add separate a module for the api package. Feb 13, 2025
Copy link
Member

@theSuess theSuess left a comment

Choose a reason for hiding this comment

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

Left a last comment but looks good to me otherwise!

@theSuess
Copy link
Member

The linter has a small correction for the typeoverrides imports as well.

You'll also need to run make api-docs and make helm/docs to fix the CI issues.

@github-actions github-actions bot added the documentation Issues relating to documentation, missing, non-clear etc. label Feb 17, 2025
@theSuess theSuess added this pull request to the merge queue Feb 19, 2025
Merged via the queue into grafana:master with commit 0d9b894 Feb 19, 2025
15 checks passed
@diurnalist
Copy link
Contributor

diurnalist commented Feb 19, 2025

@boris-smidt-klarrio @theSuess since this PR was merged, I'm having issues w/ my local environment. I can't seem to get the modules in a good state. i have tried go clean -modcache as one step but am still having issues:

go: finding module for package github.com/grafana/grafana-operator/v5/controllers/metrics
go: found github.com/grafana/grafana-operator/v5/controllers/metrics in github.com/grafana/grafana-operator/v5 v5.16.0
go: github.com/grafana/grafana-operator/v5/api: ambiguous import: found package github.com/grafana/grafana-operator/v5/api in multiple modules:
        github.com/grafana/grafana-operator/v5 v5.16.0 (/Users/jason.anderson/go/pkg/mod/github.com/grafana/grafana-operator/v5@v5.16.0/api)
        github.com/grafana/grafana-operator/v5/api (/Users/jason.anderson/dev/src/github.com/diurnalist/grafana-operator/api)
go: github.com/grafana/grafana-operator/v5/api/v1beta1: ambiguous import: found package github.com/grafana/grafana-operator/v5/api/v1beta1 in multiple modules:
        github.com/grafana/grafana-operator/v5 v5.16.0 (/Users/jason.anderson/go/pkg/mod/github.com/grafana/grafana-operator/v5@v5.16.0/api/v1beta1)
        github.com/grafana/grafana-operator/v5/api (/Users/jason.anderson/dev/src/github.com/diurnalist/grafana-operator/api/v1beta1)

any ideas how to resolve this?


update: i think it is due to my feature branch adding a dependency on controllers/metrics from w/in the API module :( - i will have to move this.


resolved: addressed in 8d0c441

diurnalist added a commit to diurnalist/grafana-operator that referenced this pull request Feb 19, 2025
since grafana#1856, the api module is separated. this poses problems
with the approach to have the CRs expose which metrics correspond
to their types via the GrafanaContentMetrics() function, because
we create an import loop.

recognizing that we're measuring essentially the same thing b/w
library panels and dashboards, this updates the metrics to indicate
this more explicitly.

the following changes are made to metrics:

  `grafana_operator_dashboard_requests`:
    * renamed to `grafana_operator_content_requests`, but will always have a label
      `kind="GrafanaDashboard"`.
    * renamed `dashboard` label to `resource`

  `grafana_operator_dashboard_revision_requests`:
    * renamed to `grafana_operator_revision_requests`, but will always have a label
      `kind="GrafanaDashboard"`.
    * renamed `dashboard` label to `resource`
diurnalist added a commit to diurnalist/grafana-operator that referenced this pull request Feb 19, 2025
since grafana#1856, the api module is separated. this poses problems
with the approach to have the CRs expose which metrics correspond
to their types via the GrafanaContentMetrics() function, because
we create an import loop.

recognizing that we're measuring essentially the same thing b/w
library panels and dashboards, this updates the metrics to indicate
this more explicitly.

the following changes are made to metrics:

  `grafana_operator_dashboard_requests`:
    * renamed to `grafana_operator_content_requests`, but will always have a label
      `kind="GrafanaDashboard"`.
    * renamed `dashboard` label to `resource`

  `grafana_operator_dashboard_revision_requests`:
    * renamed to `grafana_operator_revision_requests`, but will always have a label
      `kind="GrafanaDashboard"`.
    * renamed `dashboard` label to `resource`
github-merge-queue bot pushed a commit that referenced this pull request Feb 27, 2025
* add grafanalibrarypanel CRD types

this adds a new GrafanaLibraryPanel CRD, updates all the auto-generated
assets derived from the CRD type, and updates existing RBAC and Helm
definitions to reference the new type.

Co-authored-by: Matt Delaney <matt.delaney@getcruise.com>

* track library panels in grafana CR

this registers the new CRD with the Grafana CRD so that we can track
which library panels have been provisioned with the operator, similar
to how other resources are tracked.

Co-authored-by: Matt Delaney <matt.delaney@getcruise.com>

* add reconciler implementation

Co-authored-by: Matt Delaney <matt.delaney@getcruise.com>

* disallow fetching library panels from grafana.com

much of the content resolving/fetching logic is shared b/w dashboards
and library panels, but there is one awkward thing where library panels
are not currently (to my knowledge) available via grafana.com. rather
than extract just that fetch logic out and only apply it to dashboards,
i've opted to simply disable them as a source. an error will be issued
if a user tries to configure this field. it is not the most graceful
way to handle this, as it's not communicated via the CR validation, but
given the effort required to bend the code to do this "right", and
given the likelihood of somebody trying to configure a library panel
via a grafana.com url (which does not exist right now), we are choosing
the easy button.

* remove dashboard name from generic functions

* add chainsaw tests

* mark proposal as decided

* enable separate metrics for content resources

to enable dashboards and library panels to track their fetch operations
separately, split up the metrics by resource. this is accomplished by
adding a new interface method to the GrafanaContentResource, and the
returned struct holds references to the relevant metrics, if any.

this also adds an additional guard to the http round tripper so that if
no metric is defined, we don't panic.

* remove lazy folder creation and simplify logic

* move metrics out of api module

since #1856, the api module is separated. this poses problems
with the approach to have the CRs expose which metrics correspond
to their types via the GrafanaContentMetrics() function, because
we create an import loop.

recognizing that we're measuring essentially the same thing b/w
library panels and dashboards, this updates the metrics to indicate
this more explicitly.

the following changes are made to metrics:

  `grafana_operator_dashboard_requests`:
    * renamed to `grafana_operator_content_requests`, but will always have a label
      `kind="GrafanaDashboard"`.
    * renamed `dashboard` label to `resource`

  `grafana_operator_dashboard_revision_requests`:
    * renamed to `grafana_operator_revision_requests`, but will always have a label
      `kind="GrafanaDashboard"`.
    * renamed `dashboard` label to `resource`

* add backwards-compatibility for metrics and simplify reconcile

to make the dashboard url request metric backwards compatible, this
updates the signature of the roundtripper to be a bit more general,
so we can pass a function that is called at the end of the response
rather than explicitly increment a metric. this allows us to increment
multiple metrics in the case of the dashboard url request, one for the
old and one for the new.

* refactor: pass metrics to round_tripper directly

* refactor: remove intermediate structs to further simplify logic

* register invalidspec condition on validation errs

* Update api/v1beta1/grafanalibrarypanel_types.go

Co-authored-by: Steffen Baarsgaard <steff.bpoulsen@gmail.com>

* regen

---------

Co-authored-by: Matt Delaney <matt.delaney@getcruise.com>
Co-authored-by: Dominik Süß <dominik@suess.wtf>
Co-authored-by: Steffen Baarsgaard <steff.bpoulsen@gmail.com>
@weisdd weisdd added the chore label Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore documentation Issues relating to documentation, missing, non-clear etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants