Skip to content

Commit 22b8de1

Browse files
authored
Merge pull request #95 from scalyr/go-rewrite-v2-jmakar
Misc, minor cleanups/changes
2 parents 054fec5 + 588854b commit 22b8de1

File tree

11 files changed

+216
-266
lines changed

11 files changed

+216
-266
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ e2e-results/
2828

2929
# Editor
3030
.idea
31+
.*.swp

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changelog
22

3-
## 1.0.0 (Unreleased)
3+
## 3.0.0 (Unreleased)
44

55
Initial release.

Magefile.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
package main
44

55
import (
6-
"fmt"
76
// mage:import
87
build "github.com/grafana/grafana-plugin-sdk-go/build"
98
)
109

11-
// Hello prints a message (shows that you can define custom Mage targets).
12-
func Hello() {
13-
fmt.Println("hello plugin developer!")
14-
}
15-
1610
// Default configures the default target.
1711
var Default = build.BuildAll

README.md

Lines changed: 67 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ and dashboards in Grafana using data in Dataset. You may want to use this plugin
55
to allow you to visualize Dataset data next to other data sources, for instance
66
when you want to monitor many feeds on a single dashboard.
77

8-
![SystemDashboard](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/SystemDashboard.png)
8+
<!-- TODO When the go-rewrite-v2 branch gets merged into master, change these urls -->
9+
![SystemDashboard](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/SystemDashboard.png)
910

1011
With the Dataset plugin, you will be able to create and visualize your log-based
1112
metrics along side all of your other data sources. It's a great way to have a
@@ -27,7 +28,7 @@ can find documentation on API Keys [here](https://www.scalyr.com/help/api#scalyr
2728

2829
## Getting started
2930

30-
### Installing with grafana-cli
31+
### Installing the latest / stable version with grafana-cli
3132

3233
1. To install the stable version of the plugin using grafana-cli, run the following command:
3334

@@ -37,13 +38,9 @@ can find documentation on API Keys [here](https://www.scalyr.com/help/api#scalyr
3738
plugins install sentinelone-dataset-datasource
3839
```
3940

40-
2. Update your Grafana configuration in the `grafana.ini` file to allow this plugin by adding the following line:
41+
Older versions can be downloaded from [github releases](https://github.com/scalyr/scalyr-grafana-datasource-plugin/releases).
4142

42-
```bash
43-
allow_loading_unsigned_plugins = sentinelone-dataset-datasource
44-
```
45-
46-
3. Adding plugins requires a restart of your grafana server.
43+
2. Adding plugins requires a restart of your grafana server.
4744

4845
For init.d based services you can use the command:
4946

@@ -57,41 +54,60 @@ can find documentation on API Keys [here](https://www.scalyr.com/help/api#scalyr
5754
systemctl restart grafana-server
5855
```
5956

60-
If you require the development version, use the manual installation instructions.
61-
### Installing manually
57+
### Building a development version and installing manually
6258

63-
1. If you want a stable version of plugin, download the desired version from
64-
[github releases](https://github.com/scalyr/scalyr-grafana-datasource-plugin/releases).
65-
If you want the `development` version of the plugin,
66-
clone the [plugin repository](https://github.com/scalyr/scalyr-grafana-datasource-plugin)
67-
from GitHub. Switch to branch `go-rewrite-v2`
59+
1. To build and install the `development` version of the plugin, clone the
60+
[plugin repository](https://github.com/scalyr/scalyr-grafana-datasource-plugin) from GitHub.
6861

6962
```bash
7063
git clone https://github.com/scalyr/scalyr-grafana-datasource-plugin.git
7164
```
7265

73-
2. Grafana plugins exist in the directory: `/var/lib/grafana/plugins/`. Create a folder for the dataset plugin:
66+
2. Build the Golang backend (with the version defined in go.mod, currently 1.16) using Mage
7467

7568
```bash
76-
mkdir /var/lib/grafana/plugins/dataset
69+
mage
70+
```
71+
72+
This will build the executables in `dist/`
73+
74+
To install Mage (Golang make-like build tool):
75+
76+
```bash
77+
git clone https://github.com/magefile/mage $GOPATH/src/github.com/magefile/mage
78+
cd $GOPATH/src/github.com/magefile/mage
79+
git checkout tags/v1.12.1 # Specified in go.mod
80+
go run bootstrap.go
7781
```
7882

79-
3. Copy the contents of the Dataset plugin into grafana:
83+
A `mage` executable should now be in `$GOPATH/bin/`.
8084

81-
Stable version:
85+
3. Build the Typescript frontend using LTS Node (>= v14) and Yarn
8286

8387
```bash
84-
tar -xvf scalyr_grafana_plugin_51057f6.tar.gz
85-
cp -rf dist/ /var/lib/grafana/plugins/scalyr/
88+
yarn install --pure-lockfile # Install dependencies into node_modules
89+
yarn build
8690
```
8791

88-
Development version:
92+
This will build and the frontend files in `dist/`
93+
94+
To install Yarn: `npm install --global yarn`
95+
96+
97+
5. For development versions, simply copy the files to the Grafana server plugin directory
8998

9099
```bash
91-
cp -r scalyr-grafana-datasource/dist/ /var/lib/grafana/plugins/scalyr/
100+
mkdir /var/lib/grafana/plugins/dataset
101+
# copy files from dist/ into /var/lib/grafana/plugins/dataset
92102
```
93103

94-
4. Adding plugins requires a restart of your grafana server.
104+
Note that this is an unsigned plugin, and you must update your `grafana.ini` file to allow it adding the following line:
105+
106+
```bash
107+
allow_loading_unsigned_plugins = sentinelone-dataset-datasource
108+
```
109+
110+
6. Adding plugins requires a restart of your grafana server.
95111

96112
For init.d based services you can use the command:
97113

@@ -104,26 +120,44 @@ from GitHub. Switch to branch `go-rewrite-v2`
104120
```bash
105121
systemctl restart grafana-server
106122
```
123+
124+
### Package and sign the plugin
125+
126+
To sign and package the plugin for distribution:
127+
128+
```bash
129+
export GRAFANA_API_KEY=<YOUR_API_KEY>
130+
npx @grafana/toolkit plugin:sign # This creates dist/MANIFEST.txt
131+
132+
cp -r dist sentinelone-dataset-datasource
133+
zip -r sentinelone-dataset-datasource-$(jq -r .info.version sentinelone-dataset-datasource/plugin.json).zip sentinelone-dataset-datasource
134+
rm -rf sentinelone-dataset-datasource # Cleanup
135+
```
136+
137+
References
138+
- https://grafana.com/docs/grafana/latest/developers/plugins/package-a-plugin/
139+
- https://grafana.com/docs/grafana/latest/developers/plugins/sign-a-plugin/
140+
107141
### Verify the Plugin was Installed
108142

109143
1. In order to verify proper installation you must log in to your grafana instance
110144
and navigate to **Configuration Settings -> Data Sources**.
111145

112-
![ConfigDataSource](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/ConfigDataSource.png)
146+
![ConfigDataSource](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/ConfigDataSource.png)
113147

114148
2. This will take you into the configuration page. If you already have other data
115149
sources installed, you will see them show up here. Click on the **Add data source** button:
116150

117-
![DatasetConfig](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/DatasetConfig.png)
151+
![DatasetConfig](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/DatasetConfig.png)
118152

119153
3. If you enter "Dataset" in the search bar on the resulting page you should see "Dataset" grafana plugin show up as an option.
120154

121-
![SearchForPlugin](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/SearchForPlugin.png)
155+
![SearchForPlugin](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/SearchForPlugin.png)
122156

123157
4. Click on ***“Select”***. This will take you to a configuration page where you
124158
insert your API key mentioned in the prerequisite section.
125159

126-
![PluginConfig](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/PluginConfig.png)
160+
![PluginConfig](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/PluginConfig.png)
127161

128162
5. Enter these settings:
129163

@@ -141,17 +175,17 @@ using Scalyr data.
141175

142176
1. Create a new dashboard by click Create > dashboard
143177

144-
![CreateDashboard](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/CreateDashboard.png)
178+
![CreateDashboard](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/CreateDashboard.png)
145179

146180
2. In the **“New dashboard”** box, select the **“Add a new panel** icon
147181

148182
3. From the Data source dropdown, select **"Dataset"**.
149183

150-
![DataSetPlugin](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/DatasetPlugin.png)
184+
![DataSetPlugin](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/DatasetPlugin.png)
151185

152186
4. A 'Query Type' field allows to choose the type of query you wanted to search for
153187

154-
![QueryType](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/QueryType.png)
188+
![QueryType](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/QueryType.png)
155189

156190
5. 'Standard Query' - A standard query allows to search on Graph view,
157191
You can enter Graph Functions into the expression box and visualize the results. You can even enter and visualize Complex Expressions
@@ -160,13 +194,13 @@ using Scalyr data.
160194
Enter expression and click the save button. In the image below, we've added a query to graph visualized the
161195
number of log messages that contain the word "error"
162196
163-
![StandardQuery](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/StandardQuery.png)
197+
![StandardQuery](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/StandardQuery.png)
164198
165199
6. 'Power Query' - Works similar to PQ search in Dataset app. You can enter rich set of commands for transforming
166200
and manipulating data. Data can be viewed in Table format
167201
Visit [this documentation](https://app.scalyr.com/help/power-queries) for more information on building Power Queries
168202
169-
![PowerQuery](https://github.com/scalyr/scalyr-grafana-datasource-plugin/blob/go-rewrite-v2/src/img/PowerQuery.png)
203+
![PowerQuery](https://raw.githubusercontent.com/scalyr/scalyr-grafana-datasource-plugin/go-rewrite-v2/src/img/PowerQuery.png)
170204
171205
You’ve successfully installed, configured and created a graph in Grafana using Dataset data!
172206

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/grafana/grafana-starter-datasource-backend
1+
module github.com/scalyr/scalyr-grafana-datasource-plugin
22

33
go 1.16
44

pkg/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55

66
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
77
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
8-
"github.com/grafana/grafana-starter-datasource-backend/pkg/plugin"
8+
9+
"github.com/scalyr/scalyr-grafana-datasource-plugin/pkg/plugin"
910
)
1011

1112
func main() {
@@ -17,7 +18,7 @@ func main() {
1718
// from Grafana to create different instances of DataSetDatasource (per datasource
1819
// ID). When datasource configuration changed Dispose method will be called and
1920
// new datasource instance created using NewDataSetDatasource factory.
20-
if err := datasource.Manage("myorgid-simple-backend-datasource", plugin.NewDataSetDatasource, datasource.ManageOpts{}); err != nil {
21+
if err := datasource.Manage("sentinelone-dataset-datasource", plugin.NewDataSetDatasource, datasource.ManageOpts{}); err != nil {
2122
log.DefaultLogger.Error(err.Error())
2223
os.Exit(1)
2324
}

0 commit comments

Comments
 (0)