grafana

package
v0.56.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LokiDatasourceUID              = fmt.Sprintf("%sloki", datasourceUIDPrefix)
	MimirDatasourceUID             = fmt.Sprintf("%smimir", datasourceUIDPrefix)
	MimirAlertmanagerDatasourceUID = fmt.Sprintf("%smimir-alertmanager", datasourceUIDPrefix)
	TempoDatasourceUID             = fmt.Sprintf("%stempo", datasourceUIDPrefix)
)
View Source
var (
	// Datasource for Mimir Alertmanager
	DatasourceMimirAlertmanager = func() Datasource {
		return Datasource{
			Type:   "alertmanager",
			URL:    "http://mimir-alertmanager.mimir.svc:8080",
			Access: datasourceProxyAccessMode,
			JSONData: map[string]any{
				"handleGrafanaManagedAlerts": false,
				"implementation":             "mimir",
			},
		}
	}

	// Datasource for Loki
	DatasourceLoki = func() Datasource {
		return Datasource{
			Type:   "loki",
			URL:    "http://loki-gateway.loki.svc",
			Access: datasourceProxyAccessMode,
		}
	}

	// Datasource for Mimir
	DatasourceMimir = func() Datasource {
		return Datasource{
			Type:   "prometheus",
			URL:    "http://mimir-gateway.mimir.svc/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:   "Mimir Cardinality",
			UID:    fmt.Sprintf("%smimir-cardinality", datasourceUIDPrefix),
			URL:    "http://mimir-gateway.mimir.svc:8080/prometheus/api/v1/cardinality/",
			Access: datasourceProxyAccessMode,
		}
	}

	// Datasource for Tempo distributed tracing backend
	DatasourceTempo = func() Datasource {
		return Datasource{
			Type: "tempo",

			URL:    "http://tempo-query-frontend.tempo.svc:3200",
			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":    true,
				},

				"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(k8sClient client.Client, grafanaClient grafanaClient.GrafanaClient, cfg config.Config) *Service

func (*Service) ConfigureDashboard added in v0.32.0

func (s *Service) ConfigureDashboard(ctx context.Context, dashboard *dashboard.Dashboard) error

ConfigureDashboard configures a dashboard

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) (int64, error)

ConfigureOrganization creates or updates the organization in Grafana and returns the organization ID.

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 (s *Service) DeleteDashboard(ctx context.Context, dashboard *dashboard.Dashboard) error

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

func (*Service) PublishDashboard added in v0.32.0

func (s *Service) PublishDashboard(dashboard map[string]any) error

PublishDashboard creates or updates a dashboard in Grafana

func (*Service) UpsertOrganization added in v0.32.0

func (s *Service) UpsertOrganization(ctx context.Context, org *organization.Organization) error

UpsertOrganization creates or updates an organization in Grafana based on the provided domain organization.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL