grafana

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

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

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 (
	ErrUIDTooLong       = fmt.Errorf("UID is longer than %d symbols", MaxUIDLength)
	ErrUIDFormatInvalid = errors.New("invalid format of UID. Only letters, numbers, '-' and '_' are allowed")
	ErrUIDEmpty         = fmt.Errorf("UID is empty")
)
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.

func (Client) CreateFolder

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

CreateFolder creates a folder within current organization.

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, folderUid Uid, dashboardJson map[string]any, overwrite bool) (Uid, 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.

func (Client) DeleteDashboardByUid added in v0.10.0

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

DeleteDashboardByUid deletes a dashboard with the given ID within the given organization.

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.

func (Client) DeleteFolder

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

DeleteFolder deletes folder with the given Uid.

func (Client) GetDashboardByUid added in v0.10.0

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

GetDashboardByUid returns dashboard with the given id within the given organization.

func (Client) GetDatasourceByName

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

GetDatasourceByName retrieves datasource with the given name.

func (Client) GetFolderPermissions

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

GetFolderPermissions gets permissions associated to folder with the given Uid.

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.

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.

func (Client) SearchDashboards

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

SearchDashboards searches dashboard within the given organization.

func (Client) SetFolderPermissions

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

SetFolderPermissions sets permissions associated to folder with the given Uid. This operation will remove existing permissions if they're not included in the request.

func (Client) UpdateDatasource

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

UpdateDatasource updates datasource in the given organization.

type Dashboard

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

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              Uid `json:"folderUid,omitempty"`
	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            Uid            `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 Folder

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

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   Uid    `json:"uid"`
	Title string `json:"title"`
}

type Uid added in v0.16.0

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

Uid represents grafana uid type used to identify multiples ressources.

func ParseUid added in v0.16.0

func ParseUid(uid string) (Uid, error)

ParseUid parses and validates given uid.

func (Uid) MarshalJSON added in v0.16.0

func (uid Uid) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Uid) String added in v0.16.0

func (u Uid) String() string

String implements fmt.Stringer.

func (*Uid) UnmarshalJSON added in v0.16.0

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

UnmarshalJSON implements json.Unmarshaler.

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