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

fix: error toast message while configuring trigger while creating a monitor #1178

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@babel/plugin-transform-modules-commonjs": "^7.22.9",
"@elastic/elastic-eslint-config-kibana": "link:../../packages/opensearch-eslint-config-opensearch-dashboards",
"@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards",
"cypress": "9.5.4",
"cypress": "12.17.4",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we changing this? Have other plugins updated it as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the version of cypress in OpenSearch-Dashboards and the version of cypress in all the plugins should match for the frontend to run. So, set them to the same value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LMK if this needs to be updated or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted back

"husky": "^8.0.0",
"lint-staged": "^10.2.0",
"@types/react": "^16.14.23"
Expand Down Expand Up @@ -67,5 +67,6 @@
},
"engines": {
"yarn": "^1.21.1"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ class ConfigureActions extends React.Component {
description: '',
}));
} else {
backendErrorNotification(notifications, 'load', 'destinations', response.err);
// If the config index is not created, don't show the notification
if (response.totalMonitors !== 0) {
amsiglan marked this conversation as resolved.
Show resolved Hide resolved
backendErrorNotification(notifications, 'load', 'destinations', response.err);
}
}

let channels = await this.getChannels();
Expand Down
21 changes: 14 additions & 7 deletions server/services/DestinationsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,24 @@ export default class DestinationsService extends MDSEnabledClientService {
},
});
} catch (err) {
// Indices will be created when the monitor is created.
if (isIndexNotFoundError(err)) {
return res.ok({
body: { ok: false, resp: {} },
body: {
ok: false,
totalMonitors: 0,
monitors: [],
message: "Config index will be created automatically when the monitor is created"
amsiglan marked this conversation as resolved.
Show resolved Hide resolved
},
});
} else {
return res.ok({
body: {
ok: false,
err: err.message,
},
});
}
return res.ok({
body: {
ok: false,
err: err.message,
},
});
}
};

Expand Down
186 changes: 186 additions & 0 deletions server/services/DestinationsService.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import DestinationsService from "./DestinationsService";

describe("Test DestinationsService -- getDestinations", () => {
let destinationsService;
let mockContext;
let mockReq;
let mockRes;
let mockClient;

beforeEach(() => {
mockClient = jest.fn();

amsiglan marked this conversation as resolved.
Show resolved Hide resolved
mockContext = {};

mockRes = {
ok: jest.fn().mockReturnValue({ body: {} }),
};

destinationsService = new DestinationsService();
destinationsService.getClientBasedOnDataSource = jest.fn().mockReturnValue(mockClient);

});

describe("Test getDestinations", () => {

test("should successfully get destinations list -- name as sort string", async () => {
const mockReq = {
query: {
from: 0,
size: 20,
search: "",
sortDirection: "desc",
sortField: "name",
type: "ALL",
},
};

const mockResponse = {
destinations: [{
id: "1",
name: "Sample Destination",
schema_version: 1,
seq_no: 1,
primary_term: 1,
}],
totalDestinations: 1,
};
mockClient.mockResolvedValueOnce(mockResponse);

await destinationsService.getDestinations(mockContext, mockReq, mockRes);

expect(mockClient).toHaveBeenCalledWith("alerting.searchDestinations", {
sortString: "destination.name.keyword",
sortOrder: "desc",
startIndex: 0,
size: 20,
searchString: "",
destinationType: "ALL",
});
expect(mockRes.ok).toHaveBeenCalledWith({
body: {
ok: true,
destinations: [{
id: "1",
name: "Sample Destination",
schema_version: 1,
seq_no: 1,
primary_term: 1,
version: 1,
ifSeqNo: 1,
ifPrimaryTerm: 1,
}],
totalDestinations: 1,
},
});
});

test("should successfully get destinations list -- type as sort string", async () => {
const mockReq = {
query: {
from: 0,
size: 20,
search: "",
sortDirection: "desc",
sortField: "type",
type: "ALL",
},
};

const mockResponse = {
destinations: [{
id: "1",
name: "Sample Destination",
schema_version: 1,
seq_no: 1,
primary_term: 1,
}],
totalDestinations: 1,
};
mockClient.mockResolvedValueOnce(mockResponse);

await destinationsService.getDestinations(mockContext, mockReq, mockRes);

expect(mockClient).toHaveBeenCalledWith("alerting.searchDestinations", {
sortString: "destination.type",
sortOrder: "desc",
startIndex: 0,
size: 20,
searchString: "",
destinationType: "ALL",
});
expect(mockRes.ok).toHaveBeenCalledWith({
body: {
ok: true,
destinations: [{
id: "1",
name: "Sample Destination",
schema_version: 1,
seq_no: 1,
primary_term: 1,
version: 1,
ifSeqNo: 1,
ifPrimaryTerm: 1,
}],
totalDestinations: 1,
},
});
});

test("should handle index not found error", async () => {
const mockReq = {
query: {
from: 0,
size: 20,
search: "",
sortDirection: "desc",
sortField: "name",
type: "ALL",
},
};
const error = new Error();
error.statusCode = 404;
error.body = {
error: {
reason: 'Configured indices are not found: [.opendistro-alerting-config]'
}
};
mockClient.mockRejectedValueOnce(error);

await destinationsService.getDestinations(mockContext, mockReq, mockRes);

expect(mockRes.ok).toHaveBeenCalledWith({
body: {
ok: true,
resp: "Indices will be configured when the monitor is created: [.opendistro-alerting-config]"
},
});
});

test("should handle other errors", async () => {
const mockReq = {
query: {
from: 0,
size: 20,
search: "",
sortDirection: "desc",
sortField: "name",
type: "ALL",
},
};

const error = new Error("Some error");
mockClient.mockRejectedValueOnce(error);

await destinationsService.getDestinations(mockContext, mockReq, mockRes);

expect(mockRes.ok).toHaveBeenCalledWith({
body: {
ok: false,
err: "Some error"
},
});
});

});
});
55 changes: 40 additions & 15 deletions server/services/MonitorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,18 +481,28 @@ export default class MonitorService extends MDSEnabledClientService {
},
});
} catch (err) {
console.error('Alerting - MonitorService - getMonitors', err);
if (isIndexNotFoundError(err)) {
// Config index is not created unitl a monitor is created.
return res.ok({
body: { ok: false, resp: { totalMonitors: 0, monitors: [] } },
body: {
ok: false,
resp: {
totalMonitors: 0,
monitors: [],
message: "No monitors created"
}
},
});
} else {
// If the index is created, some error in retrieving the monitors.
console.error('Alerting - MonitorService - getMonitors', err);
return res.ok({
body: {
ok: false,
resp: err.message,
},
});
}
return res.ok({
body: {
ok: false,
resp: err.message,
},
});
}
};

Expand Down Expand Up @@ -594,13 +604,28 @@ export default class MonitorService extends MDSEnabledClientService {
},
});
} catch (err) {
console.error('Alerting - MonitorService - searchMonitor:', err);
return res.ok({
body: {
ok: false,
resp: err.message,
},
});
if (isIndexNotFoundError(err)) {
// Config index is not created unitl a monitor is created.
return res.ok({
body: {
ok: false,
resp: {
totalMonitors: 0,
monitors: [],
message: "No monitors created"
}
},
});
} else {
// If the index is created, some error in retrieving the monitors.
console.error('Alerting - MonitorService - searchMonitor:', err);
return res.ok({
body: {
ok: false,
resp: err.message,
},
});
}
}
};
}