Skip to content

Commit a56c5a3

Browse files
authored
Merge pull request #4 from xiangshen-dk/release
Update the files based on review feedback.
2 parents 99b0184 + abcafb9 commit a56c5a3

11 files changed

Lines changed: 85 additions & 61 deletions

File tree

CONTRIBUTING.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,52 @@ This project follows
2525

2626
## Contribution process
2727

28+
### Build the plugin
29+
30+
If you download the source, you need to build the plugin. Make sure you have all the prerequisites installed and configured:
31+
32+
- Grafana 9.0
33+
- Go 1.16+
34+
- Mage
35+
- NodeJS
36+
- yarn
37+
38+
Under the source directory, run the following commands:
39+
40+
```bash
41+
yarn install
42+
yarn build
43+
44+
#Run the following to update Grafana plugin SDK for Go dependency to the latest minor version:
45+
46+
go get -u github.com/grafana/grafana-plugin-sdk-go
47+
go mod tidy
48+
49+
#Build backend plugin binaries for Linux, Windows and Darwin to dist directory:
50+
mage -v
51+
```
52+
53+
More details, please read [the doc](https://grafana.com/tutorials/build-a-data-source-backend-plugin/).
54+
### Grafana Configuration
55+
56+
To have Grafana detect this plugin and make it available for use, two entries must be modified in the Grafana config file. See [Grafana's Documentation](https://grafana.com/docs/grafana/v9.0/setup-grafana/configure-grafana/) for more details, including the default location of the config file depending on platform.
57+
58+
First, set `paths.plugins` to point to where this repo has been downloaded locally. The final build artifacts will be under the `dist` directory:
59+
60+
```ini
61+
[paths]
62+
plugins = /Users/alice/grafana/googlecloud-logging-datasource/dist
63+
```
64+
65+
Next, update `plugins.allow_loading_unsigned_plugins` so that this plugin's ID is in the list:
66+
67+
```ini
68+
[plugins]
69+
allow_loading_unsigned_plugins = googlecloud-logging-datasource
70+
```
71+
72+
With these settings updated, we can now restart Grafana and expect the plugin to be available. The specific command to restart Grafana will depend on what platform it's running on, with the various options documented by [Grafana](https://grafana.com/docs/grafana/v9.0/setup-grafana/restart-grafana/).
73+
2874
### Code Reviews
2975

3076
All submissions, including submissions by project members, require review. We

README.md

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,28 @@ which allows users to query and visualize their Google Cloud logs in Grafana.
1111

1212
Download this plugin to the machine Grafana is running on, either using `git clone` or simply downloading it as a ZIP file. For the purpose of this guide, we'll assume the user "alice" has downloaded it into their local directory "/Users/alice/grafana/". If you are running the Grafana server using a user such as `grafana`, make sure the user has access to the directory.
1313

14-
### Build the plugin
14+
### Enable Cloud Resource Manager API
1515

16-
If you download the source, you need to build the plugin. Make sure you have all the prerequisites installed and configured:
16+
You need to enable the resource manager API. Otherwise, your cloud projects will not be displayed in the dropdown menu.
1717

18-
- Grafana 9.0
19-
- Go 1.16+
20-
- Mage
21-
- NodeJS
22-
- yarn
18+
You can following the those steps to enable it:
2319

24-
Under the source directory, run the following commands:
20+
1. Navigate to the [cloud resource manager API page](https://console.cloud.google.com/apis/library/cloudresourcemanager.googleapis.com]) in GCP and select your project
21+
2. Press the `Enable` button
2522

26-
```bash
27-
yarn install
28-
yarn build
23+
### Generate a JWT file
2924

30-
#Run the following to update Grafana plugin SDK for Go dependency to the latest minor version:
25+
1. If you don't have gcp project, add new gcp project. [link](https://cloud.google.com/resource-manager/docs/creating-managing-projects#console)
26+
2. Open the [Credentials](https://console.developers.google.com/apis/credentials) page in the Google API Console.
27+
3. Click **Create Credentials** then click **Service account**.
28+
4. On the Create service account page, enter the Service account details.
29+
5. On the `Create service account` page, fill in the `Service account details` and then click `Create and Continue`
30+
6. On the `Grant this service account access to project` section, select the `Logs Viewer` role under `Logging` to the service account. Click `Done`
31+
7. In the next step, click the service account you just created. Under the `Keys` tabl and select `Add key` and `Create new key`
32+
8. Choose key type `JSON` and click `Create`. A JSON key file will be created and downloaded to your computer
3133

32-
go get -u github.com/grafana/grafana-plugin-sdk-go
33-
go mod tidy
34-
35-
#Build backend plugin binaries for Linux, Windows and Darwin to dist directory:
36-
mage -v
37-
```
38-
39-
More details, please read [the doc](https://grafana.com/tutorials/build-a-data-source-backend-plugin/).
4034
### Grafana Configuration
4135

42-
To have Grafana detect this plugin and make it available for use, two entries must be modified in the Grafana config file. See [Grafana's Documentation](https://grafana.com/docs/grafana/v9.0/setup-grafana/configure-grafana/) for more details, including the default location of the config file depending on platform.
43-
44-
First, set `paths.plugins` to point to where this repo has been downloaded locally. The final build artifacts will be under the `dist` directory:
45-
46-
```ini
47-
[paths]
48-
plugins = /Users/alice/grafana/googlecloud-logging-datasource/dist
49-
```
50-
51-
Next, update `plugins.allow_loading_unsigned_plugins` so that this plugin's ID is in the list:
52-
53-
```ini
54-
[plugins]
55-
allow_loading_unsigned_plugins = googlecloud-logging-datasource
56-
```
57-
58-
With these settings updated, we can now restart Grafana and expect the plugin to be available. The specific command to restart Grafana will depend on what platform it's running on, with the various options documented by [Grafana](https://grafana.com/docs/grafana/v9.0/setup-grafana/restart-grafana/).
59-
60-
## Configuration
61-
6236
1. With Grafana restarted, navigate to `Configuration -> Data sources` (or the route `/datasources`)
6337
2. Click "Add data source"
6438
3. Select "Google Cloud Logging"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/GoogleCloudPlatform/cloud-logging-grafana-data-source-plugin
1+
module github.com/GoogleCloudPlatform/cloud-logging-data-source-plugin
22

33
go 1.16
44

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
"author": "Google Inc.",
1414
"license": "Apache-2.0",
1515
"devDependencies": {
16-
"@grafana/data": "latest",
17-
"@grafana/runtime": "latest",
18-
"@grafana/toolkit": "latest",
19-
"@grafana/ui": "latest",
16+
"@grafana/data": "^9.0.2",
17+
"@grafana/runtime": "^9.0.2",
18+
"@grafana/toolkit": "^9.0.2",
19+
"@grafana/ui": "^9.0.2",
2020
"@types/lodash": "latest"
2121
},
2222
"resolutions": {
@@ -26,6 +26,10 @@
2626
"node": ">=14"
2727
},
2828
"dependencies": {
29-
"@grafana/google-sdk": "^0.0.3"
29+
"@grafana/google-sdk": "^0.0.3",
30+
"@grafana/data": "^9.0.2",
31+
"@grafana/runtime": "^9.0.2",
32+
"@grafana/toolkit": "^9.0.2",
33+
"@grafana/ui": "^9.0.2"
3034
}
3135
}

pkg/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ package main
1717
import (
1818
"os"
1919

20+
"github.com/GoogleCloudPlatform/cloud-logging-data-source-plugin/pkg/plugin"
2021
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
2122
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
22-
"github.com/GoogleCloudPlatform/cloud-logging-grafana-data-source-plugin/pkg/plugin"
2323
)
2424

2525
func main() {

pkg/plugin/cloudlogging/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (c *Client) ListProjects(ctx context.Context) ([]string, error) {
113113
func (c *Client) TestConnection(ctx context.Context, projectID string) error {
114114
start := time.Now()
115115
defer func() {
116-
log.DefaultLogger.Info("Finished testConnection", "duration", time.Since(start).String())
116+
log.DefaultLogger.Debug("Finished testConnection", "duration", time.Since(start).String())
117117
}()
118118

119119
it := c.lClient.ListLogEntries(ctx, &loggingpb.ListLogEntriesRequest{
@@ -149,7 +149,7 @@ func (c *Client) ListLogs(ctx context.Context, q *Query) ([]*loggingpb.LogEntry,
149149

150150
start := time.Now()
151151
defer func() {
152-
log.DefaultLogger.Info("Finished listing logs", "duration", time.Since(start).String())
152+
log.DefaultLogger.Debug("Finished listing logs", "duration", time.Since(start).String())
153153
}()
154154

155155
it := c.lClient.ListLogEntries(ctx, &req)

pkg/plugin/cloudlogging/cloudlogging_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"errors"
1919
"testing"
2020

21+
"github.com/GoogleCloudPlatform/cloud-logging-data-source-plugin/pkg/plugin/cloudlogging"
2122
"github.com/grafana/grafana-plugin-sdk-go/data"
22-
"github.com/GoogleCloudPlatform/cloud-logging-grafana-data-source-plugin/pkg/plugin/cloudlogging"
2323
"github.com/stretchr/testify/require"
2424
"google.golang.org/genproto/googleapis/api/monitoredres"
2525
ltype "google.golang.org/genproto/googleapis/logging/type"

pkg/plugin/mocks/API.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/plugin/plugin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import (
2323
"strings"
2424
"time"
2525

26+
"github.com/GoogleCloudPlatform/cloud-logging-data-source-plugin/pkg/plugin/cloudlogging"
2627
"github.com/grafana/grafana-plugin-sdk-go/backend"
2728
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
2829
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
2930
"github.com/grafana/grafana-plugin-sdk-go/data"
30-
"github.com/GoogleCloudPlatform/cloud-logging-grafana-data-source-plugin/pkg/plugin/cloudlogging"
3131
)
3232

3333
// Make sure CloudLoggingDatasource implements required interfaces
@@ -123,7 +123,7 @@ type ListProjectsResponse struct {
123123
//
124124
// Currently only projects are fetched, other requests receive a 404
125125
func (d *CloudLoggingDatasource) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
126-
log.DefaultLogger.Info("CallResource called")
126+
// log.DefaultLogger.Info("CallResource called")
127127

128128
// Right now we only support calls to `/projects`
129129
resource := req.Path
@@ -163,7 +163,7 @@ func (d *CloudLoggingDatasource) CallResource(ctx context.Context, req *backend.
163163
// The QueryDataResponse contains a map of RefID to the response for each query, and each response
164164
// contains Frames ([]*Frame).
165165
func (d *CloudLoggingDatasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
166-
log.DefaultLogger.Info("QueryData called")
166+
// log.DefaultLogger.Info("QueryData called")
167167

168168
// create response struct
169169
response := backend.NewQueryDataResponse()
@@ -249,7 +249,7 @@ func (d *CloudLoggingDatasource) query(ctx context.Context, pCtx backend.PluginC
249249
// datasource configuration page which allows users to verify that
250250
// a datasource is working as expected.
251251
func (d *CloudLoggingDatasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
252-
log.DefaultLogger.Info("CheckHealth called")
252+
// log.DefaultLogger.Info("CheckHealth called")
253253

254254
var status = backend.HealthStatusOk
255255
settings := req.PluginContext.DataSourceInstanceSettings

pkg/plugin/plugin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"testing"
2121
"time"
2222

23-
"github.com/GoogleCloudPlatform/cloud-logging-grafana-data-source-plugin/pkg/plugin/cloudlogging"
24-
"github.com/GoogleCloudPlatform/cloud-logging-grafana-data-source-plugin/pkg/plugin/mocks"
23+
"github.com/GoogleCloudPlatform/cloud-logging-data-source-plugin/pkg/plugin/cloudlogging"
24+
"github.com/GoogleCloudPlatform/cloud-logging-data-source-plugin/pkg/plugin/mocks"
2525
"github.com/grafana/grafana-plugin-sdk-go/backend"
2626
"github.com/grafana/grafana-plugin-sdk-go/data"
2727
"github.com/stretchr/testify/mock"

0 commit comments

Comments
 (0)