Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 68f95b3

Browse files
Fix Problem with General Folder and add second Grafana Stage to docker-compose
1 parent d20a9ee commit 68f95b3

File tree

4 files changed

+40
-13
lines changed

4 files changed

+40
-13
lines changed

docker-compose.yaml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1-
grafana:
1+
version: '3'
2+
services:
3+
# Grafana stage one
4+
grafana_stage_one:
25
image: grafana/grafana:8.1.2
3-
container_name: grafana-vhv
6+
container_name: grafana_stage_one
47
environment:
5-
- GF_PANELS_DISABLE_SANITIZE_HTML=TRUE
68
- GF_SECURITY_ADMIN_PASSWORD=demo
79
- GF_PATHS_PROVISIONING=/usr/share/grafana/custom/
810
- GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=novatec-dashboardsync-datasource
911
- SSH_KNOWN_HOSTS=github.com
1012
- GF_ALLOWED_ORIGINS="http://localhost:3000"
1113
volumes:
12-
- ${PLUGIN_REPO}:/var/lib/grafana/plugins
13-
- ${GIT_SSH_KEY}:/usr/share/grafana/.GF_PANELS_DISABLE_SANITIZE_HTML
14+
- ${PLUGIN_REPO}:/var/lib/grafana/plugins/
15+
- ${GIT_SSH_KEY}:/usr/share/grafana/.ssh
1416
ports:
1517
- 3001:3000
18+
19+
# Grafana stage two
20+
grafana_stage_two:
21+
image: grafana/grafana:8.1.2
22+
container_name: grafana_stage_two
23+
environment:
24+
- GF_SECURITY_ADMIN_PASSWORD=demo
25+
- GF_PATHS_PROVISIONING=/usr/share/grafana/custom/
26+
- GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=novatec-dashboardsync-datasource
27+
- SSH_KNOWN_HOSTS=github.com
28+
- GF_ALLOWED_ORIGINS="http://localhost:3000"
29+
volumes:
30+
- ${PLUGIN_REPO}:/var/lib/grafana/plugins/
31+
- ${GIT_SSH_KEY}:/usr/share/grafana/.ssh
32+
ports:
33+
- 3002:3000
34+

pkg/plugin/git_api.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func (gitApi GitApi) PullRepo(repository git.Repository) {
154154
log.DefaultLogger.Error("worktree error" , "error", err)
155155
return
156156
} else {
157+
log.DefaultLogger.Debug("Pulling from Repo")
157158
err := w.Pull(&git.PullOptions{
158159
RemoteName: "origin",
159160
Auth: gitApi.authenticator,
@@ -186,30 +187,34 @@ func (gitApi GitApi) GetFileContent() map[string]map[string][]byte {
186187
fileMap := make(map[string]map[string][]byte)
187188

188189
for _, dir := range dirMap {
190+
// prepare fileMap for dir
191+
fileMap[dir] = make(map[string][]byte)
192+
189193
// read current in memory filesystem to get files
190194
files, err := gitApi.inMemoryFileSystem.ReadDir("./" + dir + "/")
191195
if err != nil {
192-
log.DefaultLogger.Error("inMemoryFileSystem error", "error", err)
196+
log.DefaultLogger.Error("inMemoryFileSystem ReadDir error", "error", err)
193197
return nil
194198
}
195199

196200
for _, file := range files {
197201

202+
log.DefaultLogger.Debug("file", "name", file.Name())
203+
198204
if file.IsDir() {
199205
continue
200206
}
201207

202-
src, err := gitApi.inMemoryFileSystem.Open(file.Name())
208+
src, err := gitApi.inMemoryFileSystem.Open("./" + dir + "/" + file.Name())
203209

204210
if err != nil {
205-
log.DefaultLogger.Error("inMemoryFileSystem error", "error", err)
211+
log.DefaultLogger.Error("inMemoryFileSystem Open error", "error", err)
206212
return nil
207213
}
208214
byteFile, err := ioutil.ReadAll(src)
209215
if err != nil {
210216
log.DefaultLogger.Error("read error", "error", err)
211217
} else {
212-
fileMap[dir] = make(map[string][]byte)
213218
fileMap[dir][file.Name()] = byteFile
214219
src.Close()
215220
}

pkg/plugin/grafana_api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (grafanaApi GrafanaApi) UpdateDashboardObjectByID(dashboard sdk.Board, fold
5151
func (grafanaApi GrafanaApi) CreateFolder(folderName string) int {
5252
folder := sdk.Folder{Title: folderName}
5353
folder, err := grafanaApi.grafanaClient.CreateFolder(context.Background(), folder)
54-
if err != nil {
54+
if err != nil && folderName != "General" {
5555
log.DefaultLogger.Error("get folders error", "error", err.Error())
5656
}
5757
return folder.ID
@@ -61,7 +61,7 @@ func (grafanaApi GrafanaApi) CreateFolder(folderName string) int {
6161
func (grafanaApi GrafanaApi) GetOrCreateFolderID(folderName string) int {
6262
folders, err := grafanaApi.grafanaClient.GetAllFolders(context.Background())
6363
if err != nil {
64-
log.DefaultLogger.Error("get folders error", "error", err.Error())
64+
log.DefaultLogger.Error("get all folders error", "error", err.Error())
6565
}
6666
for _, folder := range folders {
6767
if folder.Title == folderName {
@@ -87,7 +87,7 @@ func (grafanaApi GrafanaApi) CreateDashboardObjects(fileMap map[string]map[strin
8787
if err != nil {
8888
log.DefaultLogger.Error("set dashboard error", "error", err.Error())
8989
}
90-
log.DefaultLogger.Info("Dashboard created", "name", dashboardName)
90+
log.DefaultLogger.Debug("Dashboard created", "name", dashboardName)
9191
}
9292
}
9393
}

pkg/plugin/plugin.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (d *SampleDatasource) Dispose() {
4444
// datasource configuration page which allows users to verify that
4545
// a datasource is working as expected.
4646
func (d *SampleDatasource) CheckHealth(_ context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
47-
log.DefaultLogger.Info("CheckHealth called", "request", req)
47+
log.DefaultLogger.Debug("Backend called with following request", "request", req)
4848

4949
uiProperties := make(map[string]string)
5050
_ = json.Unmarshal(req.PluginContext.DataSourceInstanceSettings.JSONData, &uiProperties)
@@ -82,12 +82,15 @@ func (d *SampleDatasource) CheckHealth(_ context.Context, req *backend.CheckHeal
8282
return nil, err
8383
}
8484
gitApi.FetchRepo(*repository)
85+
gitApi.PullRepo(*repository)
8586
fileMap := gitApi.GetFileContent()
8687
grafanaApi.CreateDashboardObjects(fileMap)
8788
log.DefaultLogger.Info("Dashboards created")
8889
}
8990

9091
if push == "true" {
92+
log.DefaultLogger.Info("Push to git repo", "url", pushGitURL)
93+
9194
gitApi := NewGitApi(pushGitURL, privateKeyFilePath)
9295
repository, err := gitApi.CloneRepo()
9396
if err != nil {

0 commit comments

Comments
 (0)