Skip to content

Commit

Permalink
health check updates (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesoreyeram authored Feb 7, 2024
1 parent 18c1f24 commit 4d98c54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ cypress/report.json

.eslintcache
__debug_bin
mage_output_file.go
8 changes: 6 additions & 2 deletions pkg/github/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package github
import (
"context"
"fmt"
"strings"

"github.com/grafana/github-datasource/pkg/dfutil"
githubclient "github.com/grafana/github-datasource/pkg/github/client"
Expand Down Expand Up @@ -183,10 +184,13 @@ func (d *Datasource) HandleWorkflowUsageQuery(ctx context.Context, query *models
// CheckHealth is the health check for GitHub
func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
_, err := GetAllRepositories(ctx, d.client, models.ListRepositoriesOptions{
Owner: "grafana",
Owner: "grafana",
Repository: "github-datasource",
})

if err != nil {
if strings.Contains(err.Error(), "401 Unauthorized") {
return newHealthResult(backend.HealthStatusError, "401 Unauthorized. check your API key/Access token")
}
return newHealthResult(backend.HealthStatusError, "Health check failed")
}

Expand Down

0 comments on commit 4d98c54

Please sign in to comment.