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 test for metrics service monitor config line #551

Merged
merged 3 commits into from
Nov 21, 2023
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
29 changes: 16 additions & 13 deletions tests/e2e/60-telemetry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,36 @@ test.describe('Metrics', () => {
await nav.pserver('default', 'Metrics')
})

test('Install Monitoring', async({ nav }) => {
test('Install Monitoring', async({ ui, nav }) => {
// Monitoring is not installed
await telPage.toBeIncomplete('monitoring')
await expect(telPage.configBtn).toBeDisabled()
// Install Monitoring
await telPage.monitoringBtn.click()
await ui.button('Install App').click()
await apps.installChart(monitoringChart, {
navigate : false,
timeout : 7 * 60_000,
yamlPatch: `{"prometheus": {"additionalServiceMonitors": [{
"name": "kubewarden",
"selector": {"matchLabels": {"app": "kubewarden-policy-server-default"}},
"namespaceSelector": {"matchNames": ["cattle-kubewarden-system"]},
"endpoints": [{"port": "metrics","interval": "10s"}]
}]}}`
navigate: false,
timeout : 7 * 60_000
})
// Monitoring is installed
await nav.pserver('default', 'Metrics')
await telPage.toBeComplete('monitoring')
})

test('Create Grafana ConfigMaps', async() => {
// ConfigMaps are not created
test('Create Prometheus ServiceMonitor', async({ ui }) => {
// ServiceMonitor does not exist
await telPage.toBeIncomplete('servicemonitor')
await expect(telPage.configBtn).toBeDisabled()
// Create service monitor
await ui.button('Add Service Monitor').click()
await telPage.toBeComplete('servicemonitor')
})

test('Create Grafana ConfigMaps', async({ ui }) => {
// ConfigMap does not exist
await telPage.toBeIncomplete('configmap')
await expect(telPage.configBtn).toBeDisabled()
// Create configmaps
await telPage.configmapBtn.click()
await ui.button('Add Grafana Dashboards').click()
await telPage.toBeComplete('configmap')
})

Expand Down
22 changes: 22 additions & 0 deletions tests/e2e/components/rancher-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ export class RancherUI {
await this.page.keyboard.insertText(jsyaml.dump(cmYaml))
}

@step
async importYaml(yaml: YAMLPatch) {
// Open import dialog
const dialog = this.page.getByRole('dialog')
await this.page.locator('header').locator('button').filter({ has: this.page.locator('i.icon-upload') }).click()
await expect(dialog.getByRole('heading', { name: 'Import YAML', exact: true })).toBeVisible()

// Paste yaml
await this.editYaml(yaml)
await this.button('Import').click()
await expect(dialog.getByRole('heading', { name: /^Applied \d+ Resources?$/ })).toBeVisible()

// Wait until all resources are active
await dialog.getByTestId('sortable-cell-0-0').waitFor()
for (const e of await dialog.getByTestId(/sortable-cell-\d+-0/).all()) {
await expect(e).toHaveText('Active', { timeout: 60_000 })
}

// Close dialog
await this.button('Close').click()
}

/**
* Call ui.withReload(async()=> { <code> }, 'Reason')
*/
Expand Down
23 changes: 11 additions & 12 deletions tests/e2e/pages/telemetry.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import type { Locator, Page } from '@playwright/test'
import { expect } from '@playwright/test'
import { BasePage } from './basepage'

type ChecklistLine = 'otel' | 'jaeger' | 'monitoring' | 'configmap' | 'config'
type ChecklistLine = 'otel' | 'jaeger' | 'monitoring' | 'servicemonitor' | 'configmap' | 'config'

function getLine(tab: Page|Locator, text: string|RegExp) {
return tab.locator('div.checklist__step:visible', { hasText: text })
}

export class TelemetryPage extends BasePage {
readonly tracingTab: Locator
readonly metricsTab: Locator
readonly configBtn: Locator
readonly monitoringBtn: Locator
readonly configmapBtn: Locator
readonly lines: Record<ChecklistLine, Locator>

constructor(page: Page) {
Expand All @@ -18,17 +20,14 @@ export class TelemetryPage extends BasePage {
this.metricsTab = page.locator('section#policy-metrics:visible')

this.lines = {
otel : this.page.getByTestId(/^kw-(tracing|monitoring)-checklist-step-open-tel$/).filter({ has: this.page.locator(':visible') }),
jaeger : this.tracingTab.getByTestId('kw-tracing-checklist-step-jaeger'),
monitoring: this.metricsTab.getByTestId('kw-monitoring-checklist-step-monitoring-app'),
configmap : this.metricsTab.getByTestId('kw-monitoring-checklist-step-config-map'),
config : this.metricsTab.getByTestId('kw-monitoring-checklist-step-controller-config').or(
this.tracingTab.getByTestId('kw-tracing-checklist-step-config')
)
otel : getLine(page, /^The OpenTelemetry Operator/),
jaeger : getLine(this.tracingTab, /^The Jaeger Operator/),
monitoring : getLine(this.metricsTab, /^The Rancher Monitoring app/),
servicemonitor: getLine(this.metricsTab, /^A Service Monitor/),
configmap : getLine(this.metricsTab, /^Grafana Dashboards/),
config : getLine(page, /^(Tracing must be configured|The Kubewarden Controller)/)
}
this.configBtn = this.lines.config.getByRole('button', { name: /^(Edit|Update) Config$/ })
this.monitoringBtn = this.lines.monitoring.getByRole('button', { name: 'Install App' })
this.configmapBtn = this.lines.configmap.getByRole('button', { name: 'Add Grafana Dashboards' })
}

goto(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.39.0",
"@playwright/test": "^1.40.0",
"@types/js-yaml": "^4.0.5",
"@types/lodash": "^4.14.201",
"js-yaml": "^4.1.0",
Expand Down
28 changes: 14 additions & 14 deletions tests/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# yarn lockfile v1


"@playwright/test@^1.39.0":
version "1.39.0"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.39.0.tgz#d10ba8e38e44104499e25001945f07faa9fa91cd"
integrity sha512-3u1iFqgzl7zr004bGPYiN/5EZpRUSFddQBra8Rqll5N0/vfpqlP9I9EXqAoGacuAbX6c9Ulg/Cjqglp5VkK6UQ==
"@playwright/test@^1.40.0":
version "1.40.0"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.40.0.tgz#d06c506977dd7863aa16e07f2136351ecc1be6ed"
integrity sha512-PdW+kn4eV99iP5gxWNSDQCbhMaDVej+RXL5xr6t04nbKLCBwYtA046t7ofoczHOm8u6c+45hpDKQVZqtqwkeQg==
dependencies:
playwright "1.39.0"
playwright "1.40.0"

"@types/js-yaml@^4.0.5":
version "4.0.5"
Expand Down Expand Up @@ -41,16 +41,16 @@ lodash@^4.17.21:
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

playwright-core@1.39.0:
version "1.39.0"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.39.0.tgz#efeaea754af4fb170d11845b8da30b2323287c63"
integrity sha512-+k4pdZgs1qiM+OUkSjx96YiKsXsmb59evFoqv8SKO067qBA+Z2s/dCzJij/ZhdQcs2zlTAgRKfeiiLm8PQ2qvw==
playwright-core@1.40.0:
version "1.40.0"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.40.0.tgz#82f61e5504cb3097803b6f8bbd98190dd34bdf14"
integrity sha512-fvKewVJpGeca8t0ipM56jkVSU6Eo0RmFvQ/MaCQNDYm+sdvKkMBBWTE1FdeMqIdumRaXXjZChWHvIzCGM/tA/Q==

playwright@1.39.0:
version "1.39.0"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.39.0.tgz#184c81cd6478f8da28bcd9e60e94fcebf566e077"
integrity sha512-naE5QT11uC/Oiq0BwZ50gDmy8c8WLPRTEWuSSFVG2egBka/1qMoSqYQcROMT9zLwJ86oPofcTH2jBY/5wWOgIw==
playwright@1.40.0:
version "1.40.0"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.40.0.tgz#2a1824b9fe5c4fe52ed53db9ea68003543a99df0"
integrity sha512-gyHAgQjiDf1m34Xpwzaqb76KgfzYrhK7iih+2IzcOCoZWr/8ZqmdBw+t0RU85ZmfJMgtgAiNtBQ/KS2325INXw==
dependencies:
playwright-core "1.39.0"
playwright-core "1.40.0"
optionalDependencies:
fsevents "2.3.2"