diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe3b2e9..333a3a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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: @@ -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 }} @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index fcc0db7..d069f41 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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-.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-.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-.zip -d mongodb-datasource diff --git a/pkg/plugin/datasource.go b/pkg/plugin/datasource.go index 0c2da5e..c61e6f4 100644 --- a/pkg/plugin/datasource.go +++ b/pkg/plugin/datasource.go @@ -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 { @@ -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" { @@ -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