Skip to content

Commit

Permalink
Merge branch 'master' into make-int-double-compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
haohanyang authored Oct 10, 2024
2 parents 08942ca + e6f6dd6 commit aa943ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ on:
push:
branches:
- '*'
paths-ignore:
- README.md
pull_request:
branches:
- master
- main
paths-ignore:
- README.md

permissions: read-all
permissions:
contents: write

jobs:
build:
Expand All @@ -20,6 +25,7 @@ jobs:
plugin-version: ${{ steps.metadata.outputs.plugin-version }}
has-e2e: ${{ steps.check-for-e2e.outputs.has-e2e }}
has-backend: ${{ steps.check-for-backend.outputs.has-backend }}
artifact-url: ${{ steps.archive-build.outputs.artifact-url }}
env:
GRAFANA_ACCESS_POLICY_TOKEN: ${{ secrets.GRAFANA_ACCESS_POLICY_TOKEN }}
services:
Expand Down Expand Up @@ -108,6 +114,7 @@ jobs:
- name: Archive Build
uses: actions/upload-artifact@v4
id: archive-build
with:
name: ${{ steps.metadata.outputs.plugin-id }}-${{ steps.metadata.outputs.plugin-version }}
path: ${{ steps.metadata.outputs.plugin-id }}
Expand Down Expand Up @@ -205,3 +212,19 @@ jobs:
# name: playwright-report-${{ matrix.GRAFANA_IMAGE.NAME }}-v${{ matrix.GRAFANA_IMAGE.VERSION }}-${{github.run_id}}
# path: playwright-report/
# retention-days: 5

update-latest-artifact-link:
needs: [playwright-tests, build]
runs-on: ubuntu-latest
name: Update link to the latest artifact
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update the latest workflow artifact URL
if: github.ref == 'refs/heads/master'
run: |
sed -i 's|\[Download the latest build\](.*)|\[Download the latest build\](${{ needs.build.outputs.artifact-url }})|' README.md
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git commit -am "Update link to the latest workflow artifact"
git push
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Grafana MongoDB data source
![example branch parameter](https://github.com/haohanyang/mongodb-datasource/actions/workflows/ci.yml/badge.svg?branch=master)

This plugin provides a Grafana datasource for querying and visualizing data from MongoDB.

![screenshot](/static/screenshot.png)

## Download
[Download the latest build](https://github.com/haohanyang/mongodb-datasource/actions/runs/11220959466/artifacts/2025339789)


## Use
### Query language
The query text should be a valid MongoDB Aggregate pipeline - an array consisting of MongoDB Aggregate operations. Your may use the Grafana's built-in variables `"$__from"` and `"$__to"` to query data based on the current panel's time range. The plugin supports JSON and JavaScript query languages. In JSON query, you need to enter the database in the UI. Here is an example of JSON query.
Expand Down Expand Up @@ -119,7 +124,7 @@ Table type is more flexible and doesn't require the output schema. This usually


## Install
* Download the artifact package plugin `haohanyang-mongodb-datasource-<version>.zip` from GitHub Action page to the root directory (where the `docker-compose.yaml` exists) and extract files to folder `mongodb-datasource`
* Download the packaged plugin `haohanyang-mongodb-datasource-<version>.zip` from [workflow artifacts](#download) to the root directory (where `docker-compose.yaml` exists) and extract files to folder `mongodb-datasource`

```bash
unzip haohanyang-mongodb-datasource-<version>.zip -d mongodb-datasource
Expand Down
6 changes: 2 additions & 4 deletions pkg/plugin/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ func NewDatasource(ctx context.Context, source backend.DataSourceInstanceSetting
return nil, errors.New("authentication method not supported")
}

serverAPI := options.ServerAPI(options.ServerAPIVersion1)
opts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPI)
opts := options.Client().ApplyURI(uri)

client, err := mongo.Connect(ctx, opts)
if err != nil {
Expand Down Expand Up @@ -186,7 +185,6 @@ func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRe
return res, nil
}

serverAPI := options.ServerAPI(options.ServerAPIVersion1)
var uri string

if config.AuthMethod == "auth-none" {
Expand All @@ -204,7 +202,7 @@ func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRe
return res, nil
}

opts := options.Client().ApplyURI(uri).SetServerAPIOptions(serverAPI).SetTimeout(5 * time.Second)
opts := options.Client().ApplyURI(uri).SetTimeout(5 * time.Second)
client, err := mongo.Connect(ctx, opts)
if err != nil {
res.Status = backend.HealthStatusError
Expand Down

0 comments on commit aa943ed

Please sign in to comment.