Documentation ¶
Index ¶
- Constants
- Variables
- func CheckHealth(ctx context.Context, d Datasource, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
- func GetDatasourceOpts() datasource.ServeOpts
- func GetQueryHandlers(s *Server) *datasource.QueryTypeMux
- func GetRouter(h Handlers) *mux.Router
- func HandleQueryData(ctx context.Context, d Datasource, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func UnmarshalQuery(b []byte, v interface{}) *backend.DataResponse
- type CachedDatasource
- func (c *CachedDatasource) CheckHealth(ctx context.Context) error
- func (c *CachedDatasource) Cleanup()
- func (c *CachedDatasource) HandleCommitsQuery(ctx context.Context, q *models.CommitsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (c *CachedDatasource) HandleContributorsQuery(ctx context.Context, q *models.ContributorsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (c *CachedDatasource) HandleIssuesQuery(ctx context.Context, q *models.IssuesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (c *CachedDatasource) HandleLabelsQuery(ctx context.Context, q *models.LabelsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (c *CachedDatasource) HandleMilestonesQuery(ctx context.Context, q *models.MilestonesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (c *CachedDatasource) HandlePackagesQuery(ctx context.Context, q *models.PackagesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (c *CachedDatasource) HandlePullRequestsQuery(ctx context.Context, q *models.PullRequestsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (c *CachedDatasource) HandleReleasesQuery(ctx context.Context, q *models.ReleasesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (c *CachedDatasource) HandleRepositoriesQuery(ctx context.Context, q *models.RepositoriesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (c *CachedDatasource) HandleTagsQuery(ctx context.Context, q *models.TagsQuery, req backend.DataQuery) (dfutil.Framer, error)
- type CachedResult
- type Datasource
- type Handler
- func (cr *Handler) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
- func (cr *Handler) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (cr *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Handlers
- type Instance
- func (i *Instance) CheckHealth(ctx context.Context) error
- func (i *Instance) HandleCommitsQuery(ctx context.Context, q *models.CommitsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (i *Instance) HandleContributorsQuery(ctx context.Context, q *models.ContributorsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (i *Instance) HandleIssuesQuery(ctx context.Context, q *models.IssuesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (i *Instance) HandleLabelsQuery(ctx context.Context, q *models.LabelsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (i *Instance) HandleMilestonesQuery(ctx context.Context, q *models.MilestonesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (i *Instance) HandlePackagesQuery(ctx context.Context, q *models.PackagesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (i *Instance) HandlePullRequestsQuery(ctx context.Context, q *models.PullRequestsQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (i *Instance) HandleReleasesQuery(ctx context.Context, q *models.ReleasesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (i *Instance) HandleRepositoriesQuery(ctx context.Context, q *models.RepositoriesQuery, req backend.DataQuery) (dfutil.Framer, error)
- func (i *Instance) HandleTagsQuery(ctx context.Context, q *models.TagsQuery, req backend.DataQuery) (dfutil.Framer, error)
- type QueryHandlerFunc
- type Server
- func (s *Server) HandleCommits(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (s *Server) HandleContributors(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (s *Server) HandleIssues(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (s *Server) HandleLabels(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (s *Server) HandleMilestones(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (s *Server) HandlePackages(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (s *Server) HandlePullRequests(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (s *Server) HandleReleases(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (s *Server) HandleRepositories(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (s *Server) HandleTags(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
Constants ¶
const CacheCleanupInterval = time.Minute * 10
CacheCleanupInterval is the interval at which the internal cache is cleaned / garbage collected
const CacheDuration = time.Minute * 5
CacheDuration is a constant that defines how long to keep cached elements before they are refreshed
Variables ¶
var ErrNoValue = errors.New("no cached value was found with that key")
ErrNoValue is returned when a cached value is not available in the local cache
Functions ¶
func CheckHealth ¶
func CheckHealth(ctx context.Context, d Datasource, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
CheckHealth ensures that the datasource settings are able to retrieve data from GitHub
func GetDatasourceOpts ¶
func GetDatasourceOpts() datasource.ServeOpts
GetDatasourceOpts returns the datasource.ServeOpts for this plugin
func GetQueryHandlers ¶
func GetQueryHandlers(s *Server) *datasource.QueryTypeMux
GetQueryHandlers creates the QueryTypeMux type for handling queries
func HandleQueryData ¶
func HandleQueryData(ctx context.Context, d Datasource, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandleQueryData handles the `QueryData` request for the Github datasource
func UnmarshalQuery ¶
func UnmarshalQuery(b []byte, v interface{}) *backend.DataResponse
UnmarshalQuery attempts to unmarshal a query from JSON
Types ¶
type CachedDatasource ¶
type CachedDatasource struct {
// contains filtered or unexported fields
}
The CachedDatasource wraps the Datasource type and stores an internal map, and responds to queries with cached data. If there is no cached data to respond with, the CachedDatasource forwards the request to the Datasource
func WithCaching ¶
func WithCaching(datasource Datasource) *CachedDatasource
WithCaching accepts a Client and returns a CachedClient which wraps the provided Client
func (*CachedDatasource) CheckHealth ¶
func (c *CachedDatasource) CheckHealth(ctx context.Context) error
CheckHealth forwards the request to the datasource and does not perform any caching
func (*CachedDatasource) Cleanup ¶
func (c *CachedDatasource) Cleanup()
Cleanup removes old cache keys
func (*CachedDatasource) HandleCommitsQuery ¶
func (c *CachedDatasource) HandleCommitsQuery(ctx context.Context, q *models.CommitsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleCommitsQuery is the cache wrapper for the issue query handler
func (*CachedDatasource) HandleContributorsQuery ¶
func (c *CachedDatasource) HandleContributorsQuery(ctx context.Context, q *models.ContributorsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleContributorsQuery is the cache wrapper for the issue query handler
func (*CachedDatasource) HandleIssuesQuery ¶
func (c *CachedDatasource) HandleIssuesQuery(ctx context.Context, q *models.IssuesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleIssuesQuery is the cache wrapper for the issue query handler
func (*CachedDatasource) HandleLabelsQuery ¶
func (c *CachedDatasource) HandleLabelsQuery(ctx context.Context, q *models.LabelsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleLabelsQuery is the cache wrapper for the issue query handler
func (*CachedDatasource) HandleMilestonesQuery ¶
func (c *CachedDatasource) HandleMilestonesQuery(ctx context.Context, q *models.MilestonesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleMilestonesQuery is the cache wrapper for the issue query handler
func (*CachedDatasource) HandlePackagesQuery ¶
func (c *CachedDatasource) HandlePackagesQuery(ctx context.Context, q *models.PackagesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandlePackagesQuery is the cache wrapper for the issue query handler
func (*CachedDatasource) HandlePullRequestsQuery ¶
func (c *CachedDatasource) HandlePullRequestsQuery(ctx context.Context, q *models.PullRequestsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandlePullRequestsQuery is the cache wrapper for the issue query handler
func (*CachedDatasource) HandleReleasesQuery ¶
func (c *CachedDatasource) HandleReleasesQuery(ctx context.Context, q *models.ReleasesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleReleasesQuery is the cache wrapper for the issue query handler
func (*CachedDatasource) HandleRepositoriesQuery ¶ added in v1.0.1
func (c *CachedDatasource) HandleRepositoriesQuery(ctx context.Context, q *models.RepositoriesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleRepositoriesQuery is the cache wrapper for the issue query handler
type CachedResult ¶
CachedResult is a value and a timestamp that defines when the cached value is no longer usable
type Datasource ¶
type Datasource interface { HandleRepositoriesQuery(context.Context, *models.RepositoriesQuery, backend.DataQuery) (dfutil.Framer, error) HandleIssuesQuery(context.Context, *models.IssuesQuery, backend.DataQuery) (dfutil.Framer, error) HandleCommitsQuery(context.Context, *models.CommitsQuery, backend.DataQuery) (dfutil.Framer, error) HandleTagsQuery(context.Context, *models.TagsQuery, backend.DataQuery) (dfutil.Framer, error) HandleReleasesQuery(context.Context, *models.ReleasesQuery, backend.DataQuery) (dfutil.Framer, error) HandleContributorsQuery(context.Context, *models.ContributorsQuery, backend.DataQuery) (dfutil.Framer, error) HandlePullRequestsQuery(context.Context, *models.PullRequestsQuery, backend.DataQuery) (dfutil.Framer, error) HandleLabelsQuery(context.Context, *models.LabelsQuery, backend.DataQuery) (dfutil.Framer, error) HandlePackagesQuery(context.Context, *models.PackagesQuery, backend.DataQuery) (dfutil.Framer, error) HandleMilestonesQuery(context.Context, *models.MilestonesQuery, backend.DataQuery) (dfutil.Framer, error) CheckHealth(context.Context) error }
The Datasource type handles the requests sent to the datasource backend
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the plugin entrypoint and implements all of the necessary handler functions for dataqueries, healthchecks, and resources.
func (*Handler) CheckHealth ¶
func (cr *Handler) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
CheckHealth handles health checks sent from Grafana to the plugin. The main use case for these health checks is the test button on the datasource configuration page which allows users to verify that a datasource is working as expected.
func (*Handler) QueryData ¶
func (cr *Handler) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
QueryData handles multiple queries and returns multiple responses. req contains the queries []DataQuery (where each query contains RefID as a unique identifer). The QueryDataResponse contains a map of RefID to the response for each query, and each response contains Frames ([]*Frame).
type Handlers ¶
type Handlers struct { Labels http.HandlerFunc Milestones http.HandlerFunc }
Handlers stores the list of http.HandlerFunc functions for the different resource calls
type Instance ¶
type Instance struct { Datasource Datasource Handlers Handlers }
Instance is the root Datasource implementation that wraps a Datasource
func NewGitHubInstance ¶
NewGitHubInstance creates a new GitHubInstance using the settings to determine if things like the Caching Wrapper should be enabled
func (*Instance) CheckHealth ¶
CheckHealth ...
func (*Instance) HandleCommitsQuery ¶
func (i *Instance) HandleCommitsQuery(ctx context.Context, q *models.CommitsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleCommitsQuery ...
func (*Instance) HandleContributorsQuery ¶
func (i *Instance) HandleContributorsQuery(ctx context.Context, q *models.ContributorsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleContributorsQuery ...
func (*Instance) HandleIssuesQuery ¶
func (i *Instance) HandleIssuesQuery(ctx context.Context, q *models.IssuesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleIssuesQuery ...
func (*Instance) HandleLabelsQuery ¶
func (i *Instance) HandleLabelsQuery(ctx context.Context, q *models.LabelsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleLabelsQuery ...
func (*Instance) HandleMilestonesQuery ¶
func (i *Instance) HandleMilestonesQuery(ctx context.Context, q *models.MilestonesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleMilestonesQuery ...
func (*Instance) HandlePackagesQuery ¶
func (i *Instance) HandlePackagesQuery(ctx context.Context, q *models.PackagesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandlePackagesQuery ...
func (*Instance) HandlePullRequestsQuery ¶
func (i *Instance) HandlePullRequestsQuery(ctx context.Context, q *models.PullRequestsQuery, req backend.DataQuery) (dfutil.Framer, error)
HandlePullRequestsQuery ...
func (*Instance) HandleReleasesQuery ¶
func (i *Instance) HandleReleasesQuery(ctx context.Context, q *models.ReleasesQuery, req backend.DataQuery) (dfutil.Framer, error)
HandleReleasesQuery ...
type QueryHandlerFunc ¶
QueryHandlerFunc is the function signature used for mux.HandleFunc
type Server ¶
type Server struct {
Datasource Datasource
}
Server is the main handler for datasource queries. It forwards requests to the embedded datasource interface.
func (*Server) HandleCommits ¶
func (s *Server) HandleCommits(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandleCommits handles the plugin query for github Commits
func (*Server) HandleContributors ¶
func (s *Server) HandleContributors(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandleContributors handles the plugin query for github Contributors
func (*Server) HandleIssues ¶
func (s *Server) HandleIssues(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandleIssues handles the plugin query for github Issues
func (*Server) HandleLabels ¶
func (s *Server) HandleLabels(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandleLabels handles the plugin query for github Labels
func (*Server) HandleMilestones ¶
func (s *Server) HandleMilestones(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandleMilestones handles the plugin query for github Milestones
func (*Server) HandlePackages ¶
func (s *Server) HandlePackages(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandlePackages handles the plugin query for github Packages
func (*Server) HandlePullRequests ¶
func (s *Server) HandlePullRequests(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandlePullRequests handles the plugin query for github PullRequests
func (*Server) HandleReleases ¶
func (s *Server) HandleReleases(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandleReleases handles the plugin query for github Releases
func (*Server) HandleRepositories ¶ added in v1.0.1
func (s *Server) HandleRepositories(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandleRepositories handles the plugin query for github tags
func (*Server) HandleTags ¶
func (s *Server) HandleTags(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
HandleTags handles the plugin query for github tags