Documentation
¶
Index ¶
- Variables
- func WaitHealthy(logger log.Logger, c Client, maxRetry int)
- type Client
- func (c Client) AddUserToOrg(ctx context.Context, orgId OrgId, loginOrEmail string, role Role) error
- 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) CurrentOrg(ctx context.Context) (OrgId, 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) DeleteOrg(ctx context.Context, orgId OrgId) error
- func (c Client) FindOrgByName(ctx context.Context, name string) (OrgId, 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) GetOrCreateOrg(ctx context.Context, name string) (OrgId, error)
- func (c Client) GetOrgByID(ctx context.Context, orgId OrgId) (string, 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) ListOrgUsers(ctx context.Context, orgId OrgId) ([]OrgUser, error)
- func (c Client) RemoveUserFromOrg(ctx context.Context, orgId OrgId, userId UserId) 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
- func (c Client) UpdateOrgName(ctx context.Context, orgId OrgId, name string) error
- func (c Client) UpdateUserRole(ctx context.Context, orgId OrgId, userId UserId, role Role) error
- type Dashboard
- type DashboardID
- type DashboardMetadata
- type Datasource
- type DatasourceID
- type Folder
- type FolderID
- type FolderPermission
- type FolderPermissionLevel
- type OrgId
- type OrgUser
- type Role
- type SearchDashboardResult
- type User
- type UserId
Constants ¶
This section is empty.
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") ErrGrafanaOrgNotFound = errors.New("grafana org not found") ErrGrafanaUserAlreadyInOrg = errors.New("grafana user already in org") )
var (
ErrGrafanaUserNotFound = errors.New("grafana user not found")
)
Functions ¶
Types ¶
type Client ¶
type Client struct {
// Lock is required for request that require a specific user context.
// https://grafana.com/docs/grafana/latest/developers/http_api/user/#switch-user-context-for-a-specified-user
*sync.Mutex
// contains filtered or unexported fields
}
Client define an API client for grafana.
func ProvideClient ¶
Provide is a wire provider for Client.
func (Client) AddUserToOrg ¶
func (c Client) AddUserToOrg(ctx context.Context, orgId OrgId, loginOrEmail string, role Role) error
AddUserToOrg adds the given user to the given organization with the given role. If user is already part of organization, ErrGrafanaUserAlreadyInOrg will be returned. If user is not found, ErrGrafanaUserNotFound will be returned. Any other error will return a generic error.
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 ¶
CreateFolder creates a folder within current organization. This method rely on user context and therefor, client mutex.
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.
This method rely on user context and therefor, client mutex.
func (Client) CurrentOrg ¶
CurrentOrg returns current/focused/active organization of client user.
func (Client) DeleteDashboardByUID ¶
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 ¶
DeleteDatasourceByName deletes datasource with the given name inside the given organization. This method rely on user context and therefor, client mutex.
func (Client) DeleteFolder ¶
DeleteFolder deletes folder with the given FolderID. This method rely on user context and therefor, client mutex.
func (Client) FindOrgByName ¶
FindOrgByName retrieves organization id using it's name. If it fails an error is returned. ErrGrafanaOrgNotFound is returned if no organization has the given name.
func (Client) GetDashboardByUID ¶
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) GetOrCreateOrg ¶
GetOrCreateOrg retrieve organization id with the given name or create it.
func (Client) GetOrgByID ¶
GetOrgByID retrieves organization name using it's id. If it fails an error is returned. ErrGrafanaOrgNotFound is returned if no organization has the given id.
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. 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) ListOrgUsers ¶
ListOrgUsers returns the list of users part of the given organization.
func (Client) RemoveUserFromOrg ¶
RemoveUserFromOrg removes the given user from the given organization.
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 ¶
UpdateDatasource updates datasource in the given organization. This method rely on user context and therefor, client mutex.
func (Client) UpdateOrgName ¶
UpdateOrgName updates organization name with the given id.
type Dashboard ¶
type Dashboard struct {
Dashboard map[string]any `json:"dashboard"`
Metadata DashboardMetadata `json:"meta"`
}
type DashboardID ¶
DashboardID define a unique dashboard identifier.
func ParseDashboardID ¶
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) UnmarshalJSON ¶
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 ¶
DatasourceID define a unique dashboard identifier.
func ParseDatasourceID ¶
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 ¶
func (did DatasourceID) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (DatasourceID) String ¶
func (did DatasourceID) String() string
String implements fmt.Stringer.
func (*DatasourceID) UnmarshalJSON ¶
func (did *DatasourceID) UnmarshalJSON(rawJSON []byte) error
UnmarshalJSON implements json.Unmarshaler.
type FolderID ¶
FolderID define a unique dashboard identifier.
func ParseFolderID ¶
ParseFolderID parses the given string and return a FolderID if its valid. A valid FolderID is a valid UUID v4.
func (FolderID) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*FolderID) UnmarshalJSON ¶
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"`
}
User define a grafana user.