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

[Backport 2.15] [BUG] Change time format to UTC in notification message preview (#1183) #1185

Merged
merged 5 commits into from
Jan 10, 2025
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
10 changes: 5 additions & 5 deletions .github/workflows/cypress-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
branches:
- "**"
env:
OPENSEARCH_DASHBOARDS_VERSION: '2.x'
ALERTING_PLUGIN_BRANCH: '2.x'
OPENSEARCH_DASHBOARDS_VERSION: '2.15'
ALERTING_PLUGIN_BRANCH: '2.15'
jobs:
tests:
name: Run Cypress E2E tests
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Run OpenSearch Dashboards server
run: |
cd OpenSearch-Dashboards
yarn start --no-base-path --no-watch --server.host="0.0.0.0" &
yarn start --no-base-path --no-watch --server.host="0.0.0.0" --opensearch.ignoreVersionMismatch=true &
sleep 300
# timeout 300 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:5601/api/status)" != "200" ]]; do sleep 5; done'
- name: Run Cypress tests
Expand All @@ -76,13 +76,13 @@ jobs:
command: yarn run cypress run

# Screenshots are only captured on failure, will change this once we do visual regression tests
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: OpenSearch-Dashboards/plugins/alerting-dashboards-plugin/cypress/screenshots
# Test run video was always captured, so this action uses "always()" condition
- uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v4
if: always()
with:
name: cypress-videos
Expand Down
2 changes: 1 addition & 1 deletion cypress/fixtures/sample_composite_level_monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"name": "sample_channel",
"destination_id": "6dYFw4gB2qeAWe54NgyL",
"message_template": {
"source": "Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.\n - Trigger: {{ctx.trigger.name}}\n - Severity: {{ctx.trigger.severity}}\n - Period start: {{ctx.periodStart}}\n - Period end: {{ctx.periodEnd}}",
"source": "Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.\n - Trigger: {{ctx.trigger.name}}\n - Severity: {{ctx.trigger.severity}}\n - Period start: {{ctx.periodStart}} UTC\n - Period end: {{ctx.periodEnd}} UTC",
"lang": "mustache"
},
"throttle_enabled": false,
Expand Down
15 changes: 10 additions & 5 deletions cypress/integration/acknowledge_alerts_modal_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const QUERY_TRIGGER = 'sample_alerts_flyout_query_level_trigger';

const TWENTY_SECONDS = 20000;

const SIXTY_SECONDS = 60000;

describe('AcknowledgeAlertsModal', () => {
before(() => {
// Delete any existing monitors
Expand All @@ -32,20 +34,23 @@ describe('AcknowledgeAlertsModal', () => {
cy.wait(60000);

// Visit Alerting OpenSearch Dashboards
cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/monitors`);
cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/monitors`, { timeout: SIXTY_SECONDS });

// Confirm test monitors were created successfully
cy.contains(BUCKET_MONITOR, { timeout: TWENTY_SECONDS });
cy.contains(QUERY_MONITOR, { timeout: TWENTY_SECONDS });
cy.contains(BUCKET_MONITOR, { timeout: SIXTY_SECONDS });
cy.contains(QUERY_MONITOR, { timeout: SIXTY_SECONDS });

// Wait 1 minute for the test monitors to trigger alerts, then go to the 'Alerts by trigger' dashboard page to view alerts
cy.wait(60000);
});

beforeEach(() => {
// Reloading the page to close any modals that were not closed by other tests that had failures.
cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/dashboard`);

// Confirm dashboard is displaying rows for the test monitors.
cy.contains(BUCKET_MONITOR, { timeout: TWENTY_SECONDS });
cy.contains(QUERY_MONITOR, { timeout: TWENTY_SECONDS });
cy.contains(BUCKET_MONITOR, { timeout: SIXTY_SECONDS });
cy.contains(QUERY_MONITOR, { timeout: SIXTY_SECONDS });
});

it('Acknowledge button disabled when more than 1 trigger selected', () => {
Expand Down
3 changes: 3 additions & 0 deletions cypress/integration/bucket_level_monitor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ describe('Bucket-Level Monitors', () => {
// Click Edit button
cy.contains('Edit').click({ force: true });

// Wait for page to load
cy.contains('Select clusters').click({ force: true });

// Click on the Index field and type in multiple index names to replicate the bug
cy.get('#index')
.click({ force: true })
Expand Down
6 changes: 6 additions & 0 deletions cypress/integration/query_level_monitor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ describe('Query-Level Monitors', () => {
// Click Edit button
cy.contains('Edit', { timeout: 20000 }).click({ force: true });

// Wait for page to load
cy.contains('Select clusters').click({ force: true });

// Click on the Index field and type in multiple index names to replicate the bug
cy.get('#index')
.click({ force: true })
Expand Down Expand Up @@ -318,6 +321,9 @@ describe('Query-Level Monitors', () => {
// Select visual editor
cy.get('[data-test-subj="visualEditorRadioCard"]').click();

// Wait for page to load
cy.contains('Select clusters').click({ force: true });

// Wait for input to load and then type in the index name
cy.get('#index').type(`{backspace}${INDEX.SAMPLE_DATA_ECOMMERCE}{enter}`, { force: true });

Expand Down
8 changes: 7 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ Cypress.Commands.overwrite('request', (originalFn, ...args) => {
});

Cypress.Commands.add('createMonitor', (monitorJSON) => {
cy.request('POST', `${Cypress.env('opensearch')}${API.MONITOR_BASE}`, monitorJSON);
cy.request({
method: 'POST',
url: `${Cypress.env('opensearch')}${API.MONITOR_BASE}`,
body: monitorJSON,
timeout: 60000
});
});

Cypress.Commands.add('createAndExecuteMonitor', (monitorJSON) => {
Expand Down Expand Up @@ -182,6 +187,7 @@ Cypress.Commands.add('loadSampleEcommerceData', () => {
method: 'POST',
headers: { 'osd-xsrf': 'opensearch-dashboards' },
url: `${Cypress.env('opensearch_dashboards')}/api/sample_data/ecommerce`,
timeout: 60000,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getRenderWrapper(customProps = {}) {
action={{
message_template: {
source:
'Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.\n- Trigger: {{ctx.trigger.name}}\n- Severity: {{ctx.trigger.severity}}\n- Period start: {{ctx.periodStart}}\n- Period end: {{ctx.periodEnd}}',
'Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.\n- Trigger: {{ctx.trigger.name}}\n- Severity: {{ctx.trigger.severity}}\n- Period start: {{ctx.periodStart}} UTC\n- Period end: {{ctx.periodEnd}} UTC',
lang: 'mustache',
},
}}
Expand Down
8 changes: 4 additions & 4 deletions public/pages/CreateTrigger/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const DEFAULT_MESSAGE_SOURCE = {
Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.
- Trigger: {{ctx.trigger.name}}
- Severity: {{ctx.trigger.severity}}
- Period start: {{ctx.periodStart}}
- Period end: {{ctx.periodEnd}}
- Period start: {{ctx.periodStart}} UTC
- Period end: {{ctx.periodEnd}} UTC

- Deduped Alerts:
{{#ctx.dedupedAlerts}}
Expand All @@ -33,8 +33,8 @@ export const DEFAULT_MESSAGE_SOURCE = {
Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.
- Trigger: {{ctx.trigger.name}}
- Severity: {{ctx.trigger.severity}}
- Period start: {{ctx.periodStart}}
- Period end: {{ctx.periodEnd}}
- Period start: {{ctx.periodStart}} UTC
- Period end: {{ctx.periodEnd}} UTC
`.trim(),
};

Expand Down
6 changes: 4 additions & 2 deletions public/pages/CreateTrigger/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ export const conditionToExpressions = (condition = '', monitors) => {
};

export function getTimeZone() {
const detectedTimeZone = getUISettings().get('dateFormat:tz', 'Browser');
return detectedTimeZone === 'Browser' ? (moment.tz.guess() || moment.format('Z')) : detectedTimeZone;
// TODO: Include support to configure timezones rather than using the default UTC as requested here - https://github.com/opensearch-project/alerting/issues/1744
// const detectedTimeZone = getUISettings().get('dateFormat:tz', 'Browser');
// return detectedTimeZone === 'Browser' ? (moment.tz.guess() || moment.format('Z')) : detectedTimeZone;
return "UTC";
}
167 changes: 166 additions & 1 deletion public/pages/CreateTrigger/utils/helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import _ from 'lodash';
import { getDefaultScript } from './helper';
import { getDefaultScript, getTriggerContext, getTimeZone } from './helper';
import { MONITOR_TYPE } from '../../../utils/constants';
import {
FORMIK_INITIAL_DOC_LEVEL_SCRIPT,
Expand All @@ -14,6 +14,8 @@ import {
API_TYPES,
DEFAULT_CLUSTER_METRICS_SCRIPT,
} from '../../CreateMonitor/components/ClusterMetricsMonitor/utils/clusterMetricsMonitorConstants';
import moment from 'moment-timezone';
import { formikToTrigger } from '../containers/CreateTrigger/utils/formikToTrigger';

describe('CreateTrigger/utils/helper', () => {
describe('getDefaultScript', () => {
Expand Down Expand Up @@ -81,4 +83,167 @@ describe('CreateTrigger/utils/helper', () => {
});
});
});

describe('getTriggerContext', () => {
test("Should return a proper trigger context", () => {
const mockMonitor = {
"name": "Test",
"type": "monitor",
"monitor_type": "query_level_monitor",
"enabled": true,
"schedule": {
"period": {
"interval": 1,
"unit": "MINUTES"
}
},
"inputs": [
{
"search": {
"indices": [
"opensearch_dashboards_sample_data_ecommerce"
],
"query": {
"size": 0,
"aggregations": {},
"query": {
"bool": {
"filter": [
{
"range": {
"order_date": {
"gte": "{{period_end}}||-1h",
"lte": "{{period_end}}",
"format": "epoch_millis"
}
}
}
]
}
}
}
}
}
],
"triggers": [],
"ui_metadata": {
"schedule": {
"timezone": null,
"frequency": "interval",
"period": {
"interval": 1,
"unit": "MINUTES"
},
"daily": 0,
"weekly": {
"mon": false,
"tue": false,
"wed": false,
"thur": false,
"fri": false,
"sat": false,
"sun": false
},
"monthly": {
"type": "day",
"day": 1
},
"cronExpression": "0 */1 * * *"
},
"monitor_type": "query_level_monitor",
"search": {
"searchType": "graph",
"timeField": "order_date",
"aggregations": [],
"groupBy": [],
"bucketValue": 1,
"bucketUnitOfTime": "h",
"filters": []
}
}
};
const mockInputResults = {
results: [
{
"_shards": {
"total": 1,
"failed": 0,
"successful": 1,
"skipped": 0
},
"hits": {
"hits": [],
"total": {
"value": 33,
"relation": "eq"
},
"max_score": null
},
"took": 3,
"timed_out": false,
"aggregations": {
"over": {
"buckets": [
{
"key_as_string": "2025-01-06T08:00:00.000-08:00",
"doc_count": 8,
"key": 1736179200000
},
{
"key_as_string": "2025-01-06T09:00:00.000-08:00",
"doc_count": 4,
"key": 1736182800000
},
{
"key_as_string": "2025-01-06T10:00:00.000-08:00",
"doc_count": 8,
"key": 1736186400000
},
{
"key_as_string": "2025-01-06T11:00:00.000-08:00",
"doc_count": 7,
"key": 1736190000000
},
{
"key_as_string": "2025-01-06T12:00:00.000-08:00",
"doc_count": 5,
"key": 1736193600000
},
{
"key_as_string": "2025-01-06T13:00:00.000-08:00",
"doc_count": 1,
"key": 1736197200000
}
]
}
}
}
]
};
const mockExecuteResponse = {
period_start: "2025-01-06T21:11:41Z",
period_end: "2025-01-06T21:12:41Z",
input_results: mockInputResults,
};
const mockValues = {
name: "Test",
severity: "1",
condition: {
script: "ctx.results[0].hits.total.value > 10000"
}
};
const mockTrigger = formikToTrigger(mockValues, _.get(mockMonitor, 'ui_metadata', {}));
if (_.isArray(mockTrigger) && triggerIndex >= 0) mockTrigger = mockTrigger[triggerIndex];
const result = getTriggerContext(mockExecuteResponse, mockMonitor, mockValues);
expect(result).toEqual({
periodStart: moment.utc(_.get(mockExecuteResponse, 'period_start', Date.now())).tz(getTimeZone()).format(),
periodEnd: moment.utc(_.get(mockExecuteResponse, 'period_end', Date.now())).tz(getTimeZone()).format(),
results: [_.get(mockExecuteResponse, 'input_results.results[0]')].filter((result) => !!result),
trigger: mockTrigger,
alert: null,
error: null,
monitor: mockMonitor
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ import { MAX_ALERT_COUNT } from '../../utils/constants';
import { DEFAULT_PAGE_SIZE_OPTIONS } from '../../../Monitors/containers/Monitors/utils/constants';
import DashboardControls from '../DashboardControls';
import ContentPanel from '../../../../components/ContentPanel';
import { appendCommentsAction, queryColumns } from '../../utils/tableUtils';
import { queryColumns } from '../../utils/tableUtils';
import DashboardEmptyPrompt from '../DashboardEmptyPrompt';
import { getAlertsFindingColumn } from '../FindingsDashboard/findingsUtils';
import { getDataSourceId, getIsCommentsEnabled } from '../../../utils/helpers';
import { appendCommentsAction, getDataSourceId, getIsCommentsEnabled } from '../../../utils/helpers';

export const DEFAULT_NUM_MODAL_ROWS = 10;

Expand Down
Loading