Skip to content
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

Add missing labels permissions, fix tilt ci from ops-devenv, fix expensive e2e tests #4842

Merged
merged 25 commits into from
Aug 19, 2024
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ jobs:
git clone https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com/grafana/ops-devenv.git
git clone https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com/grafana/gops-labels.git

- name: Tilt CI - standard and expensive E2E tests
- name: Tilt CI - Expensive E2E tests
if: inputs.run-expensive-tests
shell: bash
env:
E2E_TESTS_CMD: "cd ../../grafana-plugin && yarn test:e2e-expensive"
GRAFANA_VERSION: ${{ inputs.grafana_version }}
GF_FEATURE_TOGGLES_ENABLE: "externalServiceAccounts"
ONCALL_API_URL: "http://oncall-dev-engine:8080"
GRAFANA_ADMIN_USERNAME: "irm"
GRAFANA_ADMIN_PASSWORD: "irm"
BROWSERS: ${{ inputs.browsers }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/expensive-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
# - 9.3.16
# - 9.4.13
# - 9.5.7
- 10.0.11
- 10.1.7
- 10.3.3
# TODO: fix issues with running e2e tests against Grafana v10.2.x and v10.3.x
# - 10.2.4
# - latest
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
#
- uses: slackapi/[email protected]
with:
channel-id: gops-oncall-dev
channel-id: gops-irm-dev
# yamllint disable rule:line-length
payload: |
{
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/linting-and-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,16 @@ jobs:
end-to-end-tests:
name: Standard e2e tests
uses: ./.github/workflows/e2e-tests.yml
strategy:
matrix:
grafana_version:
- 10.1.7
- 10.3.3
# TODO: fix issues with running e2e tests against Grafana v10.2.x and latest
# - 10.2.4
# - latest
fail-fast: false
with:
# TODO: fix issues with running e2e tests against Grafana v10.2.x and v10.3.x
grafana_version: 10.1.7
# grafana_version: 10.3.3
grafana_version: ${{ matrix.grafana_version }}
run-expensive-tests: false
browsers: "chromium"
11 changes: 9 additions & 2 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load('ext://uibutton', 'cmd_button', 'location', 'text_input', 'bool_input')
load("ext://configmap", "configmap_create")

grafana_url = os.getenv("GRAFANA_URL", "http://grafana:3000")
running_under_parent_tiltfile = os.getenv("TILT_PARENT", "false") == "true"
twilio_values=[
"oncall.twilio.accountSid=" + os.getenv("TWILIO_ACCOUNT_SID", ""),
Expand Down Expand Up @@ -29,6 +30,14 @@ def plugin_json():
return plugin_file
return 'NOT_A_PLUGIN'

def extra_env():
return {
"GF_APP_URL": grafana_url,
"GF_SERVER_ROOT_URL": grafana_url,
"GF_FEATURE_TOGGLES_ENABLE": "externalServiceAccounts",
"ONCALL_API_URL": "http://oncall-dev-engine:8080"
}


allow_k8s_contexts(["kind-kind"])

Expand Down Expand Up @@ -83,8 +92,6 @@ def load_grafana():
# The user/pass that you will login to Grafana with
grafana_admin_user_pass = os.getenv("GRAFANA_ADMIN_USER_PASS", "oncall")
grafana_version = os.getenv("GRAFANA_VERSION", "latest")
grafana_url = os.getenv("GRAFANA_URL", "http://grafana:3000")


if 'plugin' in profiles:
k8s_resource(
Expand Down
7 changes: 2 additions & 5 deletions grafana-plugin/e2e-tests/alerts/directPaging.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import semver from 'semver';

import { test, expect } from '../fixtures';
import { isGrafanaVersionLowerThan } from '../utils/constants';
import { clickButton, fillInInput } from '../utils/forms';
import { goToOnCallPage } from '../utils/navigation';

Expand All @@ -22,9 +21,7 @@ test('we can directly page a user', async ({ adminRolePage }) => {

const addRespondersPopup = page.getByTestId('add-responders-popup');

await addRespondersPopup[semver.lt(process.env.CURRENT_GRAFANA_VERSION, '10.3.0') ? 'getByText' : 'getByLabel'](
'Users'
).click();
await addRespondersPopup[isGrafanaVersionLowerThan('10.3.0') ? 'getByText' : 'getByLabel']('Users').click();
await addRespondersPopup.getByText(adminRolePage.userName).first().click();

// If user is not on call, confirm invitation
Expand Down
4 changes: 2 additions & 2 deletions grafana-plugin/e2e-tests/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
type APIRequestContext,
Page,
} from '@playwright/test';
import semver from 'semver';

import { VIEWER_USER_STORAGE_STATE, EDITOR_USER_STORAGE_STATE, ADMIN_USER_STORAGE_STATE } from '../playwright.config';

Expand All @@ -21,6 +20,7 @@ import {
IS_CLOUD,
IS_OPEN_SOURCE,
OrgRole,
isGrafanaVersionLowerThan,
} from './utils/constants';
import { goToOnCallPage } from './utils/navigation';

Expand Down Expand Up @@ -62,7 +62,7 @@ const idempotentlyInitializePlugin = async (page: Page) => {
if (await openPluginConfigurationButton.isVisible()) {
await openPluginConfigurationButton.click();
// Before 10.3 Admin user needs to create service account manually
if (semver.lt(process.env.CURRENT_GRAFANA_VERSION, '10.3.0')) {
if (isGrafanaVersionLowerThan('10.3.0')) {
await page.getByTestId('recreate-service-account').click();
}
await page.getByTestId('connect-plugin').click();
Expand Down
8 changes: 2 additions & 6 deletions grafana-plugin/e2e-tests/insights/insights.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import semver from 'semver';

import { test, expect } from '../fixtures';
import { resolveFiringAlert } from '../utils/alertGroup';
import { isGrafanaVersionLowerThan } from '../utils/constants';
import { createEscalationChain, EscalationStep } from '../utils/escalationChain';
import { clickButton, generateRandomValue } from '../utils/forms';
import { createIntegrationAndSendDemoAlert } from '../utils/integrations';
Expand All @@ -15,10 +14,7 @@ import { createOnCallSchedule } from '../utils/schedule';
* and use the currentGrafanaVersion fixture once this bugged is patched in playwright
* https://github.com/microsoft/playwright/issues/29608
*/
test.skip(
() => semver.lt(process.env.CURRENT_GRAFANA_VERSION, '10.0.0'),
'Insights is only available in Grafana 10.0.0 and above'
);
test.skip(() => isGrafanaVersionLowerThan('10.0.0'), 'Insights is only available in Grafana 10.0.0 and above');

/**
* skipping as these tests are currently flaky
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { test, expect } from '../fixtures';
import { isGrafanaVersionGreaterThan } from '../utils/constants';
import { clickButton, generateRandomValidLabel, openDropdown } from '../utils/forms';
import { openCreateIntegrationModal } from '../utils/integrations';
import { goToOnCallPage } from '../utils/navigation';

test.skip(
() => isGrafanaVersionGreaterThan('10.3.0'),
'Above 10.3 labels need enterprise version to validate permissions'
);

test('New label keys and labels can be created @expensive', async ({ adminRolePage }) => {
const { page } = adminRolePage;
await goToOnCallPage(page, 'integrations');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import semver from 'semver';

import { waitInMs } from 'utils/async';

import { test, expect, Page } from '../fixtures';
import { OrgRole } from '../utils/constants';
import { OrgRole, isGrafanaVersionLowerThan } from '../utils/constants';
import { goToGrafanaPage, goToOnCallPage } from '../utils/navigation';
import { createGrafanaUser, loginAndWaitTillGrafanaIsLoaded } from '../utils/users';

Expand Down Expand Up @@ -48,10 +46,7 @@ test.describe('Plugin initialization', () => {
}) => {
test.slow();

test.skip(
semver.lt(process.env.CURRENT_GRAFANA_VERSION, '10.3.0'),
'Extension is only available in Grafana 10.3.0 and above'
);
test.skip(isGrafanaVersionLowerThan('10.3.0'), 'Extension is only available in Grafana 10.3.0 and above');

// Create new editor user
const USER_NAME = `editor-${new Date().getTime()}`;
Expand Down
5 changes: 2 additions & 3 deletions grafana-plugin/e2e-tests/schedules/scheduleView.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import semver from 'semver';

import { scheduleViewToDaysInOneRow } from 'models/schedule/schedule.helpers';
import { ScheduleView } from 'models/schedule/schedule.types';
import { HTML_ID } from 'utils/DOM';

import { expect, Page, test } from '../fixtures';
import { isGrafanaVersionLowerThan } from '../utils/constants';
import { generateRandomValue } from '../utils/forms';
import { createOnCallSchedule } from '../utils/schedule';

Expand All @@ -13,7 +12,7 @@ const getNumberOfWeekdaysInFinalSchedule = async (page: Page) =>
const getScheduleViewRadioButtonLocator = (page: Page, view: ScheduleView) =>
page
.getByTestId('schedule-view-picker')
[semver.lt(process.env.CURRENT_GRAFANA_VERSION, '10.2.0') ? 'getByText' : 'getByLabel'](view, { exact: true });
[isGrafanaVersionLowerThan('10.2.0') ? 'getByText' : 'getByLabel'](view, { exact: true });

test('schedule view (week/2 weeks/month) toggler works', async ({ adminRolePage }) => {
const { page, userName } = adminRolePage;
Expand Down
13 changes: 6 additions & 7 deletions grafana-plugin/e2e-tests/users/usersActions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import semver from 'semver';

import { test, expect } from '../fixtures';
import { isGrafanaVersionLowerThan } from '../utils/constants';
import { goToOnCallPage } from '../utils/navigation';
import { verifyThatUserCanViewOtherUsers, accessProfileTabs } from '../utils/users';

Expand All @@ -26,7 +25,7 @@ test.describe('Users screen actions', () => {
const tabsToCheck = ['tab-phone-verification', 'tab-slack', 'tab-telegram'];

// After 10.3 it's been moved to global user profile
if (semver.lt(process.env.CURRENT_GRAFANA_VERSION, '10.3.0')) {
if (isGrafanaVersionLowerThan('10.3.0')) {
tabsToCheck.unshift('tab-mobile-app');
}

Expand Down Expand Up @@ -74,10 +73,10 @@ test.describe('Users screen actions', () => {
await page.waitForTimeout(2000);

await page
.locator('div')
.filter({ hasText: /^Search or filter results\.\.\.$/ })
.nth(1)
.click();
.locator('div')
.filter({ hasText: /^Search or filter results\.\.\.$/ })
.nth(1)
.click();
await page.keyboard.insertText(userName);
await page.keyboard.press('Enter');
await page.waitForTimeout(2000);
Expand Down
5 changes: 5 additions & 0 deletions grafana-plugin/e2e-tests/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import semver from 'semver';

export const BASE_URL = process.env.BASE_URL || 'http://localhost:3000';
export const MAILSLURP_API_KEY = process.env.MAILSLURP_API_KEY;

Expand All @@ -19,3 +21,6 @@ export enum OrgRole {
}

export const MOSCOW_TIMEZONE = 'Europe/Moscow';

export const isGrafanaVersionGreaterThan = (version: string) => semver.gt(process.env.CURRENT_GRAFANA_VERSION, version);
export const isGrafanaVersionLowerThan = (version: string) => semver.lt(process.env.CURRENT_GRAFANA_VERSION, version);
2 changes: 1 addition & 1 deletion grafana-plugin/e2e-tests/utils/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const verifyUserPhoneNumber = async (page: Page): Promise<void> => {
await openUserSettingsModal(page);

// go to the Phone Verification tab
await page.locator('a[aria-label="Tab Phone Verification"]').click();
await page.getByTestId('tab-phone-verification').click();

// check to see if we've already verified our phone number.. no need to do it more than once
if (await getForgetPhoneNumberButton(page).isVisible()) {
Expand Down
2 changes: 1 addition & 1 deletion grafana-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:report": "HTML_REPORT_ENABLED=true yarn test",
"test:silent": "yarn test --silent",
"test:e2e": "yarn playwright test --grep-invert @expensive",
"test:e2e-expensive": "yarn playwright test",
"test:e2e-expensive": "yarn playwright test --grep @expensive",
"test:e2e:watch": "yarn test:e2e --ui",
"test:e2e-expensive:watch": "yarn test:e2e-expensive --ui",
"test:e2e:gen": "yarn playwright codegen http://localhost:3000",
Expand Down
6 changes: 5 additions & 1 deletion grafana-plugin/src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,11 @@
{
"action": "users.roles:read",
"scope": "users:*"
}
},
{ "action": "grafana-labels-app.label:read" },
{ "action": "grafana-labels-app.label:write" },
{ "action": "grafana-labels-app.label:create" },
{ "action": "grafana-labels-app.label:delete" }
]
},
"dependencies": {
Expand Down
Loading