Skip to content

Commit

Permalink
Add ability to override synthetic monitoring base URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ashraf-basha committed Apr 6, 2023
1 parent f086390 commit 4f8dde0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Unshallow
run: git fetch --prune --unshallow

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19

- name: Release Grizzly Binaries
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39 changes: 39 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
- go mod tidy
builds:
- env:
# goreleaser does not work with CGO, it could also complicate
# usage by users in CI/CD systems like Terraform Cloud where
# they are unable to install libraries.
- CGO_ENABLED=0
main: ./cmd/grr
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X main.Version={{.Version}}'
goos:
- linux
- darwin
goarch:
- amd64
- arm
- arm64
ignore:
- goos: darwin
goarch: arm
binary: grr
archives:
- name_template: 'grr-{{ .Os }}-{{ .Arch }}'
checksum:
name_template: 'grr-sha256-checksums.txt'
algorithm: sha256
release:
# If you want to manually examine the release before its live, uncomment this line:
draft: false
changelog:
skip: true
11 changes: 10 additions & 1 deletion pkg/grafana/synthetic-monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/url"
"os"
"strconv"
"time"
Expand All @@ -28,7 +29,7 @@ import (
* them to IDs, having requested an ID<->string mapping from the API.
*/

const smBaseURL = "https://synthetic-monitoring-api.grafana.net"
var smBaseURL = "https://synthetic-monitoring-api.grafana.net"

type Probes struct {
ByID map[int64]synthetic_monitoring.Probe
Expand All @@ -42,6 +43,14 @@ func NewSyntheticMonitoringClient() (*smapi.Client, error) {
return nil, err
}

if smBaseOverrideURLFromEnv, exists := os.LookupEnv("GRAFANA_SM_URL"); exists {
smBaseOverrideURL, err := url.ParseRequestURI(smBaseOverrideURLFromEnv)
if err != nil {
return nil, fmt.Errorf("failed to parse GRAFANA_SM_URL environment variable - %v", err)
}
smBaseURL = smBaseOverrideURL.String()
}

smClient := smapi.NewClient(smBaseURL, "", client)

apiToken, ok := os.LookupEnv("GRAFANA_SM_TOKEN")
Expand Down

0 comments on commit 4f8dde0

Please sign in to comment.