Skip to content

Commit e5b0ade

Browse files
committed
doc: improve documentation and fix sonar issue
1 parent 7f933cf commit e5b0ade

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@ With the Snowflake plugin, you can visualize your Snowflake data in Grafana and
1111
#### Install the Data Source
1212

1313
1. Install the plugin into the grafana plugin folder:
14+
15+
**With grafana-cli**
1416
```shell
15-
grafana-cli --pluginUrl https://github.com/michelin/snowflake-grafana-datasource/releases/latest/download/snowflake-grafana-datasource.zip plugins install michelin-snowflake-datasource
17+
grafana cli --pluginUrl https://github.com/michelin/snowflake-grafana-datasource/releases/latest/download/snowflake-grafana-datasource.zip plugins install michelin-snowflake-datasource
1618
```
17-
or
19+
`--pluginsDir` option can be used to specify a custom plugin directory
20+
21+
**Manually**
1822
```shell
1923
cd /var/lib/grafana/plugins/
2024
wget https://github.com/michelin/snowflake-grafana-datasource/releases/latest/download/snowflake-grafana-datasource.zip
2125
unzip snowflake-grafana-datasource.zip
2226
```
2327

24-
2. Edit the grafana configuration file to allow unsigned plugins:
28+
2. Edit the grafana configuration file `grafana.ini` to allow unsigned plugins:
2529
* Linux:/etc/grafana/grafana.ini
2630
* macOS:/usr/local/etc/grafana/grafana.ini
2731
```shell
@@ -187,6 +191,12 @@ More info about snowflake-side caching: https://docs.snowflake.com/en/user-guide
187191

188192
The snowflake datasource is a data source backend plugin composed of both frontend and backend components.
189193

194+
To build the project you must have the following tools installed:
195+
* Go
196+
* Node
197+
* yarn
198+
199+
190200
### Frontend
191201

192202
1. Install dependencies

pkg/macros.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
const rsIdentifier = `([_a-zA-Z0-9]+)`
1313
const sExpr = `\$` + rsIdentifier + `\(([^\)]*)\)`
14+
const missingColumnMessage = "missing time column argument for macro %v"
1415

1516
func ReplaceAllStringSubmatchFunc(re *regexp.Regexp, str string, repl func([]string) string) string {
1617
result := ""
@@ -78,20 +79,21 @@ func SetupFillmode(configStruct *queryConfigStruct, fillmode string) error {
7879
// evaluateMacro convert macro expression to sql expression
7980
func evaluateMacro(name string, args []string, configStruct *queryConfigStruct) (string, error) {
8081
timeRange := configStruct.TimeRange
82+
8183
switch name {
8284
case "__time":
8385
if len(args) == 0 || args[0] == "" {
84-
return "", fmt.Errorf("missing time column argument for macro %v", name)
86+
return "", fmt.Errorf(missingColumnMessage, name)
8587
}
8688
return fmt.Sprintf("TRY_TO_TIMESTAMP_NTZ(%s) AS time", args[0]), nil
8789
case "__timeEpoch":
8890
if len(args) == 0 || args[0] == "" {
89-
return "", fmt.Errorf("missing time column argument for macro %v", name)
91+
return "", fmt.Errorf(missingColumnMessage, name)
9092
}
9193
return fmt.Sprintf("extract(epoch from %s) as time", args[0]), nil
9294
case "__timeFilter":
9395
if len(args) == 0 || args[0] == "" {
94-
return "", fmt.Errorf("missing time column argument for macro %v", name)
96+
return "", fmt.Errorf(missingColumnMessage, name)
9597
}
9698
column := args[0]
9799
timezone := "'UTC'"
@@ -101,7 +103,7 @@ func evaluateMacro(name string, args []string, configStruct *queryConfigStruct)
101103
return fmt.Sprintf("%s > CONVERT_TIMEZONE('UTC', %s, '%s'::timestamp_ntz) AND %s < CONVERT_TIMEZONE('UTC', %s, '%s'::timestamp_ntz)", column, timezone, timeRange.From.UTC().Format(time.RFC3339Nano), column, timezone, timeRange.To.UTC().Format(time.RFC3339Nano)), nil
102104
case "__timeTzFilter":
103105
if len(args) == 0 || args[0] == "" {
104-
return "", fmt.Errorf("missing time column argument for macro %v", name)
106+
return "", fmt.Errorf(missingColumnMessage, name)
105107
}
106108
column := args[0]
107109
return fmt.Sprintf("%s > '%s'::timestamp_tz AND %s < '%s'::timestamp_tz", column, timeRange.From.UTC().Format(time.RFC3339Nano), column, timeRange.To.UTC().Format(time.RFC3339Nano)), nil
@@ -164,12 +166,12 @@ func evaluateMacro(name string, args []string, configStruct *queryConfigStruct)
164166
return "", err
165167
case "__unixEpochFilter":
166168
if len(args) == 0 || args[0] == "" {
167-
return "", fmt.Errorf("missing time column argument for macro %v", name)
169+
return "", fmt.Errorf(missingColumnMessage, name)
168170
}
169171
return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], timeRange.From.UTC().Unix(), args[0], timeRange.To.UTC().Unix()), nil
170172
case "__unixEpochNanoFilter":
171173
if len(args) == 0 || args[0] == "" {
172-
return "", fmt.Errorf("missing time column argument for macro %v", name)
174+
return "", fmt.Errorf(missingColumnMessage, name)
173175
}
174176
return fmt.Sprintf("%s >= %d AND %s <= %d", args[0], timeRange.From.UTC().UnixNano(), args[0], timeRange.To.UTC().UnixNano()), nil
175177
case "__unixEpochNanoFrom":

0 commit comments

Comments
 (0)