Documentation ¶
Index ¶
- Constants
- Variables
- func WaitHealthy(logger zerolog.Logger, c Client, maxRetry int)
- type Client
- func (c Client) CreateDatasource(ctx context.Context, orgId OrgId, name string, srcType string, isDefault bool) (Datasource, error)
- func (c Client) CreateFolder(ctx context.Context, orgId OrgId, title string) (Folder, error)
- func (c Client) CreateOrg(ctx context.Context, name string) (OrgId, error)
- func (c Client) CreateUpdateDashboard(ctx context.Context, orgId OrgId, folder FolderId, ...) (DashboardId, error)
- func (c Client) DeleteDashboardByUid(ctx context.Context, orgId OrgId, dashboardID DashboardId) error
- func (c Client) DeleteDatasourceByName(ctx context.Context, orgId OrgId, name string) error
- func (c Client) DeleteFolder(ctx context.Context, orgId OrgId, folderId FolderId) error
- func (c Client) GetDashboardByUid(ctx context.Context, orgId OrgId, dashboardID DashboardId) (Dashboard, error)
- func (c Client) GetDatasourceByName(ctx context.Context, orgId OrgId, name string) (Datasource, error)
- func (c Client) GetFolderPermissions(ctx context.Context, orgId OrgId, folderId FolderId) ([]FolderPermission, error)
- func (c Client) HealthCheck(ctx context.Context) error
- func (c Client) ListDatasources(ctx context.Context, orgId OrgId) ([]Datasource, error)
- func (c Client) ListFolders(ctx context.Context, orgId OrgId, limit int, page int) ([]Folder, error)
- func (c Client) SearchDashboards(ctx context.Context, orgId OrgId, limit, page int) ([]SearchDashboardResult, error)
- func (c Client) SetFolderPermissions(ctx context.Context, orgId OrgId, folderId FolderId, ...) error
- func (c Client) UpdateDatasource(ctx context.Context, orgId OrgId, datasource Datasource) error
- type Dashboard
- type DashboardId
- type DashboardMetadata
- type Datasource
- type DatasourceId
- type Folder
- type FolderId
- type FolderPermission
- type FolderPermissionLevel
- type OrgId
- type Role
- type SearchDashboardResult
- type User
- type UserId
Constants ¶
const (
GrafanaOrgIdHeader = "X-Grafana-Org-Id"
)
Variables ¶
var ( ErrGrafanaDashboardAlreadyExists = errors.New("grafana dashboard already exists") ErrGrafanaDashboardNotFound = errors.New("grafana dashboard not found") )
var ( ErrGrafanaDatasourceAlreadyExists = errors.New("grafana datasource already exists") ErrGrafanaDatasourceNotFound = errors.New("grafana datasource not found") )
var ( ErrGrafanaFolderAlreadyExists = errors.New("folder with same title already exists") ErrGrafanaFolderNotFound = errors.New("folder not found") )
var (
ErrGrafanaOrgAlreadyExists = errors.New("grafana org already exists")
)
var (
ErrGrafanaUserNotFound = errors.New("grafana user not found")
)
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client define an API client for grafana.
func ProvideClient ¶
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 ¶
CreateFolder creates a folder within current organization.
func (Client) CreateOrg ¶
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.
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.
func (Client) DeleteDatasourceByName ¶
DeleteDatasourceByName deletes datasource with the given name inside the given organization.
func (Client) DeleteFolder ¶
DeleteFolder deletes folder with the given FolderId.
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.
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 FolderId) ([]FolderPermission, error)
GetFolderPermissions gets permissions associated to folder with the given FolderId.
func (Client) HealthCheck ¶
HealthCheck performs an health check request against a grafana instance.
func (Client) ListDatasources ¶
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 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.
func (Client) UpdateDatasource ¶
UpdateDatasource updates datasource in the given organization.
type Dashboard ¶
type Dashboard struct { Dashboard map[string]any `json:"dashboard"` Metadata DashboardMetadata `json:"meta"` }
type DashboardId ¶ added in v0.10.0
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
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 FolderId ¶ added in v0.10.0
FolderId define a unique dashboard identifier.
func ParseFolderId ¶ added in v0.10.0
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
MarshalJSON implements json.Marshaler.
func (*FolderId) UnmarshalJSON ¶ added in v0.10.0
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 Role ¶
type Role int8
Role enumerate possible user roles in an organization. If role is unknown, it will default to None.
func (Role) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Role) UnmarshalJSON ¶
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.