Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Fix issue that nothing is in 'Time field' dropdown when defining moni…
Browse files Browse the repository at this point in the history
…tors by visual graph (#222)

* correct the mistake in ES API calls of 'get alias, indices and mappings' during migration
* add validation for api routers of ES API calls of 'get alises, indices, and mappings'
  • Loading branch information
ftianli-amzn committed Dec 9, 2020
1 parent 48e98ea commit 777c137
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class DefineMonitor extends Component {

try {
const response = await this.props.httpClient.post('../api/alerting/_mappings', {
body: JSON.stringify(index),
body: JSON.stringify({ index }),
});
if (response.ok) {
return response.resp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MonitorIndex extends React.Component {
}
try {
const response = await this.props.httpClient.post('../api/alerting/_indices', {
body: JSON.stringify(index),
body: JSON.stringify({ index }),
});
if (response.ok) {
const indices = response.resp.map(({ health, index, status }) => ({
Expand Down Expand Up @@ -151,7 +151,7 @@ class MonitorIndex extends React.Component {

try {
const response = await this.props.httpClient.post('../api/alerting/_aliases', {
body: JSON.stringify(alias),
body: JSON.stringify({ alias }),
});
if (response.ok) {
const indices = response.resp.map(({ alias, index }) => ({ label: alias, index }));
Expand Down
12 changes: 9 additions & 3 deletions server/routes/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default function (services, router) {
{
path: '/api/alerting/_indices',
validate: {
body: schema.any(),
body: schema.object({
index: schema.string(),
}),
},
},
elasticsearchService.getIndices
Expand All @@ -42,7 +44,9 @@ export default function (services, router) {
{
path: '/api/alerting/_aliases',
validate: {
body: schema.any(),
body: schema.object({
alias: schema.string(),
}),
},
},
elasticsearchService.getAliases
Expand All @@ -52,7 +56,9 @@ export default function (services, router) {
{
path: '/api/alerting/_mappings',
validate: {
body: schema.any(),
body: schema.object({
index: schema.arrayOf(schema.string()),
}),
},
},
elasticsearchService.getMappings
Expand Down
6 changes: 3 additions & 3 deletions server/services/ElasticsearchService.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class ElasticsearchService {
getAliases = async (context, req, res) => {
try {
const { alias } = req.body;
const { callAsCurrentUser } = this.esDriver.asScoped(res);
const { callAsCurrentUser } = this.esDriver.asScoped(req);
const aliases = await callAsCurrentUser('cat.aliases', {
alias,
format: 'json',
Expand All @@ -107,9 +107,9 @@ export default class ElasticsearchService {

getMappings = async (context, req, res) => {
try {
const params = { body: JSON.stringify(req.body) };
const { index } = req.body;
const { callAsCurrentUser } = this.esDriver.asScoped(req);
const mappings = await callAsCurrentUser('indices.getMapping', params);
const mappings = await callAsCurrentUser('indices.getMapping', { index });
return res.ok({
body: {
ok: true,
Expand Down

0 comments on commit 777c137

Please sign in to comment.