forked from grafana/grizzly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Grizzly support multiple providers/endpoints (grafana#44)
* Major rewrite to add 'provider' support * Remove redundant code * Add Grafana synthetic-monitoring support * Updated testing data * Add preview, separate add/update * Add providers cmd, s/board/source/ * Fix error handling on not found * Handle data source updates * Remove unnecessary field * Add prepare/unprepare, switch to probe names from ids * Switch test data to probe names * Providers provide Handlers for Resource Types * Use Resource not MSI * Remove Plugins, no HTTP API * Dashboard folders * Remove folderName and add docs * Set defaults on datasources to quieten diffs * Switch to interface{} * Move APIErr to grizzly pkg * Fix diff on apply * (re-)fix dashboard folders * Remove extraneous file * De-java the code * handle errors * s/dashboard/something else/ * fix lint, simplify * Split handlers into two files
- Loading branch information
1 parent
f338173
commit cfe8301
Showing
24 changed files
with
1,747 additions
and
738 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package grafana | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"os" | ||
"path" | ||
) | ||
|
||
func getGrafanaURL(urlPath string) (string, error) { | ||
if grafanaURL, exists := os.LookupEnv("GRAFANA_URL"); exists { | ||
u, err := url.Parse(grafanaURL) | ||
if err != nil { | ||
return "", err | ||
} | ||
u.Path = path.Join(u.Path, urlPath) | ||
grafanaURL = u.String() | ||
if token, exists := os.LookupEnv("GRAFANA_TOKEN"); exists { | ||
user, exists := os.LookupEnv("GRAFANA_USER") | ||
if !exists { | ||
user = "api_key" | ||
} | ||
u.User = url.UserPassword(user, token) | ||
} | ||
return u.String(), nil | ||
} | ||
return "", fmt.Errorf("Require GRAFANA_URL (optionally GRAFANA_TOKEN & GRAFANA_USER") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package grizzly | ||
package grafana | ||
|
||
import ( | ||
"os" | ||
|
@@ -8,37 +8,42 @@ import ( | |
func TestParseEnvironment(t *testing.T) { | ||
tests := map[string]struct { | ||
url string | ||
path string | ||
user string | ||
token string | ||
expect string | ||
err bool | ||
}{ | ||
"GRAFANA_URL only": { | ||
"https://my.grafana.net", | ||
"/this", | ||
"", | ||
"", | ||
"https://my.grafana.net", | ||
"https://my.grafana.net/this", | ||
false, | ||
}, | ||
"w/ token": { | ||
"https://my.grafana.net", | ||
"/that", | ||
"", | ||
"token", | ||
"https://api_key:[email protected]", | ||
"https://api_key:[email protected]/that", | ||
false, | ||
}, | ||
"Basic auth": { | ||
"https://my.grafana.net", | ||
"/secure", | ||
"user", | ||
"pass", | ||
"https://user:[email protected]", | ||
"https://user:[email protected]/secure", | ||
false, | ||
}, | ||
"GRAFANA_URL blank": { | ||
"", | ||
"", | ||
"", | ||
"", | ||
"", | ||
true, | ||
}, | ||
} | ||
|
@@ -59,12 +64,12 @@ func TestParseEnvironment(t *testing.T) { | |
os.Unsetenv("GRAFANA_TOKEN") | ||
} | ||
t.Logf("Running test case, %q...", testName) | ||
cfg, err := ParseEnvironment() | ||
url, err := getGrafanaURL(test.path) | ||
if err != nil && !test.err { | ||
t.Errorf("Unexpected error getting Jsonnet files: %s", err) | ||
} | ||
if cfg != nil && cfg.GrafanaURL != test.expect { | ||
t.Errorf("Expected GrafanaURL %s, got: %s", test.expect, cfg.GrafanaURL) | ||
if url != test.expect { | ||
t.Errorf("Expected GrafanaURL %s, got: %s", test.expect, url) | ||
} | ||
} | ||
} |
Oops, something went wrong.