Skip to content

Test with multiple Grafana versions #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
grafana: ['9.5.0', '11.6.1']
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -43,31 +47,17 @@ jobs:
version: latest
args: buildAll

- name: Setup services (Trino, Grafana, PostgreSQL, Keycloak)
- name: Setup services (Trino, Grafana, Keycloak)
run: |
docker network create trino

echo "Starting PostgreSQL..."
docker run --rm --detach \
--name postgres \
--net trino \
--env POSTGRES_USER=keycloak \
--env POSTGRES_PASSWORD=keycloak \
--env POSTGRES_DB=keycloak \
postgres:17.4

echo "Starting Keycloak..."
docker run --rm --detach \
--name keycloak \
--net trino \
--publish 18080:8080 \
--env KC_BOOTSTRAP_ADMIN_USERNAME=admin \
--env KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
--env KC_DB=postgres \
--env KC_DB_URL_HOST=postgres \
--env KC_DB_URL_DATABASE=keycloak \
--env KC_DB_USERNAME=keycloak \
--env KC_DB_PASSWORD=keycloak \
--volume "$(pwd)/test-data/test-keycloak-realm.json:/opt/keycloak/data/import/realm.json" \
quay.io/keycloak/keycloak:26.1.4 \
start-dev --import-realm
Expand Down Expand Up @@ -96,10 +86,32 @@ jobs:
--publish 3000:3000 \
--volume "$(pwd):/var/lib/grafana/plugins/trino" \
--env "GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=trino-datasource" \
grafana/grafana:11.4.0
grafana/grafana:${{ matrix.grafana }}

- name: End to end test
run: |
npx tsc -p tsconfig.json --noEmit
npx playwright install
npx playwright test

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report-${{ matrix.grafana }}
path: playwright-report/
retention-days: 5

- name: Dump logs
if: always()
run: |
echo "::group::Trino logs"
docker logs trino
echo "::endgroup::"

echo "::group::Keycloak logs"
docker logs keycloak
echo "::endgroup::"

echo "::group::Grafana logs"
docker logs grafana
echo "::endgroup::"
40 changes: 19 additions & 21 deletions src/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
import { test, expect, Page } from '@playwright/test';

const GRAFANA_CLIENT = 'grafana-client';
const EXPORT_DATA = 'Explore data';
const EXPLORE_DATA = 'Explore';

async function login(page: Page) {
await page.goto('http://localhost:3000/login');
await page.getByTestId('data-testid Username input field').fill('admin');
await page.getByTestId('data-testid Password input field').fill('admin');
await page.getByTestId('data-testid Login button').click();
await page.getByTestId('data-testid Skip change password button').click();
await page.getByLabel('Username input field').fill('admin');
await page.getByLabel('Password input field').fill('admin');
await page.getByLabel('Login button').click();
await page.getByLabel('Skip change password button').click();
}

async function goToTrinoSettings(page: Page) {
await page.getByTestId('data-testid Toggle menu').click();
await page.getByLabel('Toggle menu').click();
await page.getByRole('link', {name: 'Connections'}).click();
await page.getByRole('link', {name: 'Trino'}).click();
await page.locator('.css-1yhi3xa').click();
await page.getByRole('button', {name: 'Add new data source'}).click();
await page.getByText('Create a Trino data source').click();
}

async function setupDataSourceWithAccessToken(page: Page) {
await page.getByTestId('data-testid Datasource HTTP settings url').fill('http://trino:8080');
await page.getByLabel('Datasource HTTP settings url').fill('http://trino:8080');
await page.locator('div').filter({hasText: /^Impersonate logged in userAccess token$/}).getByLabel('Toggle switch').click();
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
await page.getByTestId('data-testid Data source settings page Save and Test button').click();
await page.getByLabel('Data source settings page Save and Test button').click();
}

async function setupDataSourceWithClientCredentials(page: Page, clientId: string) {
await page.getByTestId('data-testid Datasource HTTP settings url').fill('http://trino:8080');
await page.getByLabel('Datasource HTTP settings url').fill('http://trino:8080');
await page.locator('div').filter({hasText: /^Token URL$/}).locator('input').fill('http://keycloak:8080/realms/trino-realm/protocol/openid-connect/token');
await page.locator('div').filter({hasText: /^Client id$/}).locator('input').fill(clientId);
await page.locator('div').filter({hasText: /^Client secret$/}).locator('input[type="password"]').fill('grafana-secret');
await page.locator('div').filter({hasText: /^Impersonation user$/}).locator('input').fill('service-account-grafana-client');
await page.getByTestId('data-testid Data source settings page Save and Test button').click();
await page.getByLabel('Data source settings page Save and Test button').click();
}

async function runQueryAndCheckResults(page: Page) {
await page.getByLabel(EXPORT_DATA).click();
await page.getByText(EXPLORE_DATA).click();
await page.getByTestId('data-testid TimePicker Open Button').click();
await page.getByTestId('data-testid Time Range from field').fill('1995-01-01');
await page.getByTestId('data-testid Time Range to field').fill('1995-12-31');
await page.getByLabel('Time Range from field').fill('1995-01-01');
await page.getByLabel('Time Range to field').fill('1995-12-31');
await page.getByTestId('data-testid TimePicker submit button').click();
await page.locator('div').filter({hasText: /^Format asChoose$/}).locator('svg').click();
await page.getByRole('option', {name: 'Table'}).click();
await page.getByTestId('data-testid Code editor container').click();
await page.getByLabel('Format as').click();
await page.getByText('Table', { exact: true }).click();
await page.getByTestId('data-testid RefreshPicker run button').click();
await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19 0.:00:005703857F.*/);
await expect(page.getByTestId('data-testid table body')).toContainText(/.*1995-01-19 0.:00:00.*/);
}

test('test with access token', async ({ page }) => {
Expand All @@ -66,13 +64,13 @@ test('test client credentials flow with wrong credentials', async ({ page }) =>
await login(page);
await goToTrinoSettings(page);
await setupDataSourceWithClientCredentials(page, "some-wrong-client");
await expect(page.getByLabel(EXPORT_DATA)).toHaveCount(0);
await expect(page.getByText(EXPLORE_DATA)).toHaveCount(0);
});

test('test client credentials flow with configured access token', async ({ page }) => {
await login(page);
await goToTrinoSettings(page);
await page.locator('div').filter({hasText: /^Access token$/}).locator('input[type="password"]').fill('aaa');
await setupDataSourceWithClientCredentials(page, GRAFANA_CLIENT);
await expect(page.getByLabel(EXPORT_DATA)).toHaveCount(0);
await expect(page.getByText(EXPLORE_DATA)).toHaveCount(0);
});
2 changes: 1 addition & 1 deletion src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"updated": "%TODAY%"
},
"dependencies": {
"grafanaDependency": ">=8.3.0",
"grafanaDependency": ">=9.5.0",
"plugins": []
}
}
Loading