grafana

package
v0.14.0-beta0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GrafanaOrgIdHeader = "X-Grafana-Org-Id"
)

Variables

View Source
var (
	ErrGrafanaDashboardAlreadyExists = errors.New("grafana dashboard already exists")
	ErrGrafanaDashboardNotFound      = errors.New("grafana dashboard not found")
)
View Source
var (
	ErrGrafanaDatasourceAlreadyExists = errors.New("grafana datasource already exists")
	ErrGrafanaDatasourceNotFound      = errors.New("grafana datasource not found")
)
View Source
var (
	ErrGrafanaFolderAlreadyExists = errors.New("folder with same title already exists")
	ErrGrafanaFolderNotFound      = errors.New("folder not found")
)
View Source
var (
	ErrGrafanaOrgAlreadyExists = errors.New("grafana org already exists")
)
View Source
var (
	ErrGrafanaUserNotFound = errors.New("grafana user not found")
)

Functions

func WaitHealthy

func WaitHealthy(logger zerolog.Logger, c Client, maxRetry int)

WaitHealthy checks grafana instance health status using the given config. This function panics if `maxRetry` attempt fails or are not healthy.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client define an API client for grafana.

func ProvideClient

func ProvideClient(cfg config.Grafana) Client

Provide is a wire provider for Client.

func (Client) CreateDatasource

func (c Client) CreateDatasource(ctx context.Context, orgId OrgId, name string, srcType string, isDefault bool) (Datasource, error)

CreateDatasource creates a datasource in the given organization. This method rely on user context and therefor, client mutex.

func (Client) CreateFolder

func (c Client) CreateFolder(ctx context.Context, orgId OrgId, title string) (Folder, error)

CreateFolder creates a folder within current organization. This method rely on user context and therefor, client mutex.

func (Client) CreateOrg

func (c Client) CreateOrg(ctx context.Context, name string) (OrgId, error)

CreateOrg creates an organization with the given name. If it fails an error is returned. ErrGrafanaOrgAlreadyExists is returned if name is already used by an organization.

func (Client) CreateUpdateDashboard

func (c Client) CreateUpdateDashboard(ctx context.Context, orgId OrgId, folder FolderId, dashboardJson map[string]any, overwrite bool) (DashboardId, error)

CreateUpdateDashboard creates/updates a dashboard in the given organization and folder. dashboardJson map[string]any argument must contain a "uid" and "version" fields for updates. Version field must contains version BEFORE update, that is, the current version. If overwrite is sets to true, "version" field is optional.

This method rely on user context and therefor, client mutex.

func (Client) DeleteDashboardByUid added in v0.10.0

func (c Client) DeleteDashboardByUid(ctx context.Context, orgId OrgId, dashboardID DashboardId) error

DeleteDashboardByUid deletes a dashboard with the given ID within the given organization. This method rely on user context and therefor, client mutex.

func (Client) DeleteDatasourceByName

func (c Client) DeleteDatasourceByName(ctx context.Context, orgId OrgId, name string) error

DeleteDatasourceByName deletes datasource with the given name inside the given organization. This method rely on user context and therefor, client mutex.

func (Client) DeleteFolder

func (c Client) DeleteFolder(ctx context.Context, orgId OrgId, folderId FolderId) error

DeleteFolder deletes folder with the given FolderId. This method rely on user context and therefor, client mutex.

func (Client) GetDashboardByUid added in v0.10.0

func (c Client) GetDashboardByUid(ctx context.Context, orgId OrgId, dashboardID DashboardId) (Dashboard, error)

GetDashboardByUid returns dashboard with the given id within the given organization. This method rely on user context and therefor, client mutex.

func (Client) GetDatasourceByName

func (c Client) GetDatasourceByName(ctx context.Context, orgId OrgId, name string) (Datasource, error)

GetDatasourceByName retrieves datasource with the given name. This method rely on user context and therefor, client mutex.

func (Client) GetFolderPermissions

func (c Client) GetFolderPermissions(ctx context.Context, orgId OrgId, folderId FolderId) ([]FolderPermission, error)

GetFolderPermissions gets permissions associated to folder with the given FolderId. This method rely on user context and therefor, client mutex.

func (Client) HealthCheck

func (c Client) HealthCheck(ctx context.Context) error

HealthCheck performs an health check request against a grafana instance.

func (Client) ListDatasources

func (c Client) ListDatasources(ctx context.Context, orgId OrgId) ([]Datasource, error)

ListDatasources returns a list of datasource present in the given organization. This method rely on user context and therefor, client mutex.

func (Client) ListFolders

func (c Client) ListFolders(ctx context.Context, orgId OrgId, limit int, page int) ([]Folder, error)

ListFolders lists up to the given limit, children folders of parent folder with the given folder UUID. This method rely on user context and therefor, client mutex.

func (Client) SearchDashboards

func (c Client) SearchDashboards(ctx context.Context, orgId OrgId, limit, page int) ([]SearchDashboardResult, error)

SearchDashboards searches dashboard within the given organization. This method rely on user context and therefor, client mutex.

func (Client) SetFolderPermissions

func (c Client) SetFolderPermissions(ctx context.Context, orgId OrgId, folderId FolderId, permissions ...FolderPermission) error

SetFolderPermissions sets permissions associated to folder with the given FolderId. This operation will remove existing permissions if they're not included in the request. This method rely on user context and therefor, client mutex.

func (Client) UpdateDatasource

func (c Client) UpdateDatasource(ctx context.Context, orgId OrgId, datasource Datasource) error

UpdateDatasource updates datasource in the given organization. This method rely on user context and therefor, client mutex.

type Dashboard

type Dashboard struct {
	Dashboard map[string]any    `json:"dashboard"`
	Metadata  DashboardMetadata `json:"meta"`
}

type DashboardId added in v0.10.0

type DashboardId uuid.UUID

DashboardId define a unique dashboard identifier.

func ParseDashboardId added in v0.10.0

func ParseDashboardId(dashboardID string) (DashboardId, error)

ParseDashboardId parses the given string and return a DashboardId if its valid. A valid DashboardId is a valid UUID v4.

func (DashboardId) String added in v0.10.0

func (uid DashboardId) String() string

String implements fmt.Stringer.

func (*DashboardId) UnmarshalJSON added in v0.10.0

func (uid *DashboardId) UnmarshalJSON(rawJSON []byte) error

UnmarshalJSON implements json.Unmarshaler.

type DashboardMetadata

type DashboardMetadata struct {
	AnnotationsPermissions struct {
		// contains filtered or unexported fields
	}
	CanAdmin               bool
	CanDelete              bool
	CanEdit                bool
	CanSave                bool
	CanStar                bool
	Created                time.Time
	CreatedBy              string
	Expires                time.Time
	FolderId               int64
	FolderTitle            string
	FolderUid              FolderId
	FolderUrl              string
	HasAcl                 bool
	IsFolder               bool
	IsSnapshot             bool
	IsStarred              bool
	Provisioned            bool
	ProvisionedExternalId  string
	PublicDashboardEnabled bool
	PublicDashboardUid     string
	Slug                   string
	Type                   string
	Updated                time.Time
	UpdatedBy              string
	Url                    string
	Version                int
}

type Datasource

type Datasource struct {
	Access         string         `json:"access,omitempty"`
	BasicAuth      bool           `json:"basicAuth,omitempty"`
	Database       string         `json:"database,omitempty"`
	Id             int64          `json:"id,omitempty"`
	IsDefault      bool           `json:"isDefault,omitempty"`
	JSONData       map[string]any `json:"jsonData,omitempty"`
	SecureJSONData map[string]any `json:"secureJsonData"`
	Name           string         `json:"name,omitempty"`
	OrgId          OrgId          `json:"orgId,omitempty"`
	ReadOnly       bool           `json:"readOnly,omitempty"`
	Type           string         `json:"type,omitempty"`
	TypeLogoUrl    string         `json:"typeLogoUrl,omitempty"`
	TypeName       string         `json:"typeName,omitempty"`
	Uid            DatasourceId   `json:"uid,omitempty"`
	URL            string         `json:"url,omitempty"`
	User           string         `json:"user,omitempty"`
	Version        uint           `json:"version,omitempty"`
}

Datasource define data sources for grafana dashboards.

type DatasourceId added in v0.10.0

type DatasourceId uuid.UUID

DatasourceId define a unique dashboard identifier.

func ParseDatasourceId added in v0.10.0

func ParseDatasourceId(datasourceID string) (DatasourceId, error)

ParseDatasourceId parses the given string and return a DatasourceId if its valid. A valid DatasourceId is a valid UUID v4.

func (DatasourceId) MarshalJSON added in v0.10.0

func (did DatasourceId) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (DatasourceId) String added in v0.10.0

func (did DatasourceId) String() string

String implements fmt.Stringer.

func (*DatasourceId) UnmarshalJSON added in v0.10.0

func (did *DatasourceId) UnmarshalJSON(rawJSON []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Folder

type Folder struct {
	Id        int64     `json:"id"`
	ParentUid uuid.UUID `json:"parentUid"`
	Title     string    `json:"title"`
	Uid       FolderId  `json:"uid"`
}

type FolderId added in v0.10.0

type FolderId uuid.UUID

FolderId define a unique dashboard identifier.

func ParseFolderId added in v0.10.0

func ParseFolderId(folderId string) (FolderId, error)

ParseFolderId parses the given string and return a FolderId if its valid. A valid FolderId is a valid UUID v4.

func (FolderId) MarshalJSON added in v0.10.0

func (fid FolderId) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (FolderId) String added in v0.10.0

func (fid FolderId) String() string

String implements fmt.Stringer.

func (*FolderId) UnmarshalJSON added in v0.10.0

func (fid *FolderId) UnmarshalJSON(rawJSON []byte) error

UnmarshalJSON implements json.Unmarshaler.

type FolderPermission

type FolderPermission struct {
	Permission FolderPermissionLevel `json:"permission"`
	Role       Role                  `json:"role,omitempty"`
	TeamId     int64                 `json:"teamId,omitempty"`
	UserId     UserId                `json:"userId,omitempty"`
}

type FolderPermissionLevel

type FolderPermissionLevel int8

FolderPermissionLevel enumerate possible folder permission level.

const (
	FolderPermissionLevelView FolderPermissionLevel = 1 << iota
	FolderPermissionLevelEdit
	FolderPermissionLevelAdmin
)

func (FolderPermissionLevel) String

func (fpl FolderPermissionLevel) String() string

String implements fmt.Stringer.

type OrgId

type OrgId int64

OrgId define a grafana organization id.

type Role

type Role int8

Role enumerate possible user roles in an organization. If role is unknown, it will default to None.

const (
	RoleNone Role = iota
	RoleViewer
	RoleEditor
	RoleAdmin
)

func (Role) MarshalJSON

func (r Role) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Role) String

func (r Role) String() string

String implements fmt.Stringer.

func (*Role) UnmarshalJSON

func (r *Role) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type SearchDashboardResult

type SearchDashboardResult struct {
	Uid   DashboardId `json:"uid"`
	Title string      `json:"title"`
}

type User

type User struct {
	Id                             UserId    `json:"id"`
	CreatedAt                      time.Time `json:"createdAt"`
	UpdatedAt                      time.Time `json:"updatedAt"`
	IsDisabled                     bool      `json:"isDisabled"`
	IsGrafanaAdmin                 bool      `json:"isGrafanaAdmin"`
	IsGrafanaAdminExternallySynced bool      `json:"isGrafanaAdminExternallySynced"`
	Name                           string    `json:"name"`
	Email                          string    `json:"email"`
	OrgId                          OrgId     `json:"orgId"`
}

User define a grafana user.

type UserId

type UserId int64

UserId define a grafana user id.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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