Documentation
¶
Index ¶
- Variables
- func IsZeroVar[T comparable](v T) bool
- type Datasource
- type Service
- func (s *Service) CleanupOrphanedFoldersForOrg(ctx context.Context, org *organization.Organization, ...) error
- func (s *Service) ConfigureDashboard(ctx context.Context, dashboard *dashboard.Dashboard) error
- func (s *Service) ConfigureDatasource(ctx context.Context, organization *organization.Organization) ([]Datasource, error)
- func (s *Service) ConfigureDatasources(ctx context.Context, organization *organization.Organization) ([]Datasource, error)
- func (s *Service) ConfigureOrganization(ctx context.Context, organization *organization.Organization, ...) (int64, error)
- func (s *Service) ConfigureSSOSettings(ctx context.Context, organizations []*organization.Organization) error
- func (s *Service) DeleteDashboard(ctx context.Context, dashboard *dashboard.Dashboard) error
- func (s *Service) DeleteOrganization(ctx context.Context, organization *organization.Organization) error
- func (s *Service) FindOrgByName(name string) (*organization.Organization, error)
- func (s *Service) PublishDashboard(dashboard map[string]any, folderUID string) error
- func (s *Service) UpsertOrganization(ctx context.Context, org *organization.Organization, previousName string) error
Constants ¶
This section is empty.
Variables ¶
var ( LokiDatasourceUID = fmt.Sprintf("%sloki", datasourceUIDPrefix) MimirDatasourceUID = fmt.Sprintf("%smimir", datasourceUIDPrefix) MimirAlertmanagerDatasourceUID = fmt.Sprintf("%smimir-alertmanager", datasourceUIDPrefix) TempoDatasourceUID = fmt.Sprintf("%stempo", datasourceUIDPrefix) LokiDatasourceName = datasourceNamePrefix + "Loki" MimirDatasourceName = datasourceNamePrefix + "Mimir" MimirAlertmanagerDatasourceName = datasourceNamePrefix + "Mimir Alertmanager" TempoDatasourceName = datasourceNamePrefix + "Tempo" MimirCardinalityDatasourceName = datasourceNamePrefix + "Mimir Cardinality" )
var ( // Datasource for Mimir Alertmanager DatasourceMimirAlertmanager = func() Datasource { return Datasource{ Type: "alertmanager", Access: datasourceProxyAccessMode, JSONData: map[string]any{ "handleGrafanaManagedAlerts": false, "implementation": "mimir", }, } } // Datasource for Loki DatasourceLoki = func() Datasource { return Datasource{ Type: "loki", Access: datasourceProxyAccessMode, } } // Datasource for Mimir DatasourceMimir = func() Datasource { return Datasource{ Type: "prometheus", Access: datasourceProxyAccessMode, JSONData: map[string]any{ "cacheLevel": "Medium", "httpMethod": "POST", "incrementalQuerying": true, "prometheusType": "Mimir", "prometheusVersion": "2.9.1", "timeInterval": "60s", }, } } // Datasource for Mimir to query cardinality data DatasourceMimirCardinality = func() Datasource { return Datasource{ Type: "marcusolsson-json-datasource", Name: MimirCardinalityDatasourceName, UID: fmt.Sprintf("%smimir-cardinality", datasourceUIDPrefix), Access: datasourceProxyAccessMode, } } // Datasource for Tempo distributed tracing backend DatasourceTempo = func() Datasource { return Datasource{ Type: "tempo", Access: datasourceProxyAccessMode, JSONData: map[string]any{ "serviceMap": map[string]any{ "datasourceUid": MimirDatasourceUID, }, "nodeGraph": map[string]any{ "enabled": true, }, "streamingEnabled": map[string]any{ "metrics": true, "search": true, }, "tracesToLogsV2": map[string]any{ "datasourceUid": LokiDatasourceUID, "spanStartTimeShift": "-10m", "spanEndTimeShift": "10m", "filterByTraceID": false, "customQuery": traceToLogsQuery, }, "tracesToMetrics": map[string]any{ "datasourceUid": MimirDatasourceUID, }, }, } } )
Predefined datasources These are functions to ensure a new instance is created each time so that modifications to the returned struct do not affect others. This is important when using them as templates. They can be used as-is or merged with custom settings using the Merge method.
Functions ¶
func IsZeroVar ¶ added in v0.42.0
func IsZeroVar[T comparable](v T) bool
IsZeroVar reports whether v is the zero value for its type.
Types ¶
type Datasource ¶
type Datasource struct {
ID int64
UID string
Name string
Type string
URL string
IsDefault bool
Access string
JSONData map[string]any
SecureJSONData map[string]string
}
Datasource represents a Grafana datasource.
func (Datasource) Merge ¶ added in v0.42.0
func (d Datasource) Merge(src Datasource) Datasource
Merge merges the non-zero fields from src into d and returns the result. For JSONData and SecureJSONData maps, it merges the key-value pairs, with src's values taking precedence in case of key conflicts.
type Service ¶ added in v0.32.0
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶ added in v0.32.0
func NewService(grafanaClient grafanaClient.GrafanaClient, cfg config.Config) *Service
func (*Service) CleanupOrphanedFoldersForOrg ¶ added in v0.61.0
func (s *Service) CleanupOrphanedFoldersForOrg(ctx context.Context, org *organization.Organization, requiredUIDs map[string]struct{}) error
CleanupOrphanedFoldersForOrg switches to the given organization context and removes operator-managed folders that are no longer referenced by any dashboard. requiredUIDs is the set of folder UIDs still needed by dashboard ConfigMaps.
func (*Service) ConfigureDashboard ¶ added in v0.32.0
ConfigureDashboard configures a dashboard, ensuring folder hierarchy exists and injecting managed tag
func (*Service) ConfigureDatasource ¶ added in v0.42.0
func (s *Service) ConfigureDatasource(ctx context.Context, organization *organization.Organization) ([]Datasource, error)
ConfigureDatasources ensures the datasources for the given organization are up to date. It creates, updates, or deletes datasources as necessary to match the desired state.
func (*Service) ConfigureDatasources ¶ added in v0.32.0
func (s *Service) ConfigureDatasources(ctx context.Context, organization *organization.Organization) ([]Datasource, error)
ConfigureDatasources ensures the datasources for the given organization are up to date. Returns the list of configured datasources.
func (*Service) ConfigureOrganization ¶ added in v0.32.0
func (s *Service) ConfigureOrganization(ctx context.Context, organization *organization.Organization, previousName string) (int64, error)
ConfigureOrganization creates or updates the organization in Grafana and returns the organization ID. previousName is the last display name the caller persisted for this organization (typically GrafanaOrganization.Status.DisplayName); see UpsertOrganization for how it is used.
func (*Service) ConfigureSSOSettings ¶ added in v0.32.0
func (s *Service) ConfigureSSOSettings(ctx context.Context, organizations []*organization.Organization) error
ConfigureSSOSettings configures Grafana SSO settings with organization mappings. It retrieves the current SSO provider settings, updates the org_mapping field with the provided organizations, and applies the changes to Grafana.
func (*Service) DeleteDashboard ¶ added in v0.32.0
func (*Service) DeleteOrganization ¶ added in v0.32.0
func (s *Service) DeleteOrganization(ctx context.Context, organization *organization.Organization) error
func (*Service) FindOrgByName ¶ added in v0.32.0
func (s *Service) FindOrgByName(name string) (*organization.Organization, error)
FindOrgByName is a wrapper function used to find a Grafana organization by its name. It returns organization.ErrOrganizationNotFound (wrapped) when Grafana returns 404, letting callers distinguish a missing organization from other API failures.
func (*Service) PublishDashboard ¶ added in v0.32.0
PublishDashboard creates or updates a dashboard in Grafana. folderUID specifies the target folder; empty string means the General folder.
func (*Service) UpsertOrganization ¶ added in v0.32.0
func (s *Service) UpsertOrganization(ctx context.Context, org *organization.Organization, previousName string) error
UpsertOrganization reconciles the Grafana organization described by org with Grafana's current state.
previousName is the last display name this CR successfully applied to its Grafana organization (typically GrafanaOrganization.Status.DisplayName). It lets the reconciler tell apart:
- a CR rename: Grafana still has the org at org.ID() under previousName → rename it to org.Name().
- a stale cached orgID: the org at org.ID() has a different name (and that name is not what we last wrote there), so it now belongs to someone else (e.g., Grafana's DB was reset and the ID got reassigned to another CR). We must not rename it; create a new org instead.
Pass an empty previousName for a first-time reconcile. In that case a mismatched current name is always treated as a collision (safer than assuming ownership).
On success org.ID() is set to the current Grafana org ID.