Change the name of the index_pattern api to ingest and remove the JSON API payload wrapper
This commit is contained in:
parent
2bea404c97
commit
e9810328a9
14 changed files with 98 additions and 151 deletions
|
@ -1,4 +1,4 @@
|
|||
const indexPatterns = require('./server/routes/api/index_patterns');
|
||||
const ingest = require('./server/routes/api/ingest');
|
||||
|
||||
module.exports = function (kibana) {
|
||||
return new kibana.Plugin({
|
||||
|
@ -48,7 +48,7 @@ module.exports = function (kibana) {
|
|||
},
|
||||
|
||||
init: function (server, options) {
|
||||
indexPatterns(server);
|
||||
ingest(server);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
const Joi = require('joi');
|
||||
|
||||
module.exports = function (primary, included) {
|
||||
const doc = {data: primary};
|
||||
if (included) {
|
||||
doc.included = included;
|
||||
}
|
||||
|
||||
return Joi.object(doc);
|
||||
};
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
const Joi = require('joi');
|
||||
|
||||
module.exports = function (attributes, relationships) {
|
||||
const resource = {
|
||||
type: Joi.string().required(),
|
||||
id: Joi.string().required(),
|
||||
attributes: attributes
|
||||
};
|
||||
if (relationships) {
|
||||
resource.relationships = relationships;
|
||||
}
|
||||
|
||||
return Joi.object(resource);
|
||||
};
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
const Joi = require('joi');
|
||||
|
||||
module.exports = Joi.object({
|
||||
data: Joi.object({
|
||||
type: Joi.string().required(),
|
||||
id: Joi.string().required()
|
||||
})
|
||||
});
|
||||
|
|
@ -1,36 +1,23 @@
|
|||
const Joi = require('joi');
|
||||
const createApiDocumentSchema = require('../common/create_api_document_schema');
|
||||
const createResourceObjectSchema = require('../common/create_resource_object_schema');
|
||||
const relationshipObjectSchema = require('../common/relationship_object_schema');
|
||||
|
||||
const indexPatternResourceObject = createResourceObjectSchema(
|
||||
Joi.object({
|
||||
title: Joi.string().required(),
|
||||
time_field_name: Joi.string(),
|
||||
interval_name: Joi.string(),
|
||||
not_expandable: Joi.boolean(),
|
||||
fields: Joi.array().items(
|
||||
Joi.object({
|
||||
name: Joi.string().required(),
|
||||
type: Joi.string().required(),
|
||||
count: Joi.number().integer(),
|
||||
scripted: Joi.boolean(),
|
||||
doc_values: Joi.boolean(),
|
||||
analyzed: Joi.boolean(),
|
||||
indexed: Joi.boolean(),
|
||||
script: Joi.string(),
|
||||
lang: Joi.string()
|
||||
})
|
||||
).required(),
|
||||
field_format_map: Joi.object()
|
||||
})
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
post: createApiDocumentSchema(
|
||||
Joi.alternatives().try(
|
||||
indexPatternResourceObject,
|
||||
Joi.array().items(indexPatternResourceObject)
|
||||
).required()
|
||||
)
|
||||
};
|
||||
module.exports = Joi.object({
|
||||
id: Joi.string().required(),
|
||||
title: Joi.string().required(),
|
||||
time_field_name: Joi.string(),
|
||||
interval_name: Joi.string(),
|
||||
not_expandable: Joi.boolean(),
|
||||
fields: Joi.array().items(
|
||||
Joi.object({
|
||||
name: Joi.string().required(),
|
||||
type: Joi.string().required(),
|
||||
count: Joi.number().integer(),
|
||||
scripted: Joi.boolean(),
|
||||
doc_values: Joi.boolean(),
|
||||
analyzed: Joi.boolean(),
|
||||
indexed: Joi.boolean(),
|
||||
script: Joi.string(),
|
||||
lang: Joi.string()
|
||||
})
|
||||
).required(),
|
||||
field_format_map: Joi.object()
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ const {templateToPattern, patternToTemplate} = require('../../../lib/convert_pat
|
|||
|
||||
module.exports = function registerDelete(server) {
|
||||
server.route({
|
||||
path: '/api/kibana/index_patterns/{id}',
|
||||
path: '/api/kibana/ingest/{id}',
|
||||
method: 'DELETE',
|
||||
handler: function (req, reply) {
|
||||
const callWithRequest = server.plugins.elasticsearch.callWithRequest;
|
|
@ -9,18 +9,19 @@ const initDefaultFieldProps = require('../../../lib/init_default_field_props');
|
|||
|
||||
module.exports = function registerPost(server) {
|
||||
server.route({
|
||||
path: '/api/kibana/index_patterns',
|
||||
path: '/api/kibana/ingest',
|
||||
method: 'POST',
|
||||
config: {
|
||||
validate: {
|
||||
payload: indexPatternSchema.post
|
||||
payload: indexPatternSchema
|
||||
}
|
||||
},
|
||||
handler: function (req, reply) {
|
||||
const callWithRequest = server.plugins.elasticsearch.callWithRequest;
|
||||
const requestDocument = _.cloneDeep(req.payload);
|
||||
const indexPatternId = requestDocument.data.id;
|
||||
const indexPattern = convertToCamelCase(requestDocument.data.attributes);
|
||||
const indexPatternId = requestDocument.id;
|
||||
const indexPattern = convertToCamelCase(requestDocument);
|
||||
delete indexPattern.id;
|
||||
|
||||
const mappings = createMappingsFromPatternFields(indexPattern.fields);
|
||||
indexPattern.fields = initDefaultFieldProps(indexPattern.fields);
|
|
@ -1,6 +1,6 @@
|
|||
define({
|
||||
suites: [
|
||||
'test/unit/api/index_patterns/index'
|
||||
'test/unit/api/ingest/index'
|
||||
],
|
||||
excludeInstrumentation: /(fixtures|node_modules)\//,
|
||||
loaderOptions: {
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
module.exports = function createTestData() {
|
||||
return {
|
||||
indexPattern: {
|
||||
'data': {
|
||||
'type': 'index_patterns',
|
||||
'id': 'logstash-*',
|
||||
'attributes': {
|
||||
'title': 'logstash-*',
|
||||
'time_field_name': '@timestamp',
|
||||
'fields': [{
|
||||
'name': 'ip',
|
||||
'type': 'ip'
|
||||
}, {
|
||||
'name': '@timestamp',
|
||||
'type': 'date'
|
||||
}, {
|
||||
'name': 'agent',
|
||||
'type': 'string'
|
||||
}, {
|
||||
'name': 'bytes',
|
||||
'type': 'number'
|
||||
},
|
||||
{
|
||||
'name': 'geo.coordinates',
|
||||
'type': 'geo_point'
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
|
@ -1,25 +1,25 @@
|
|||
define(function (require) {
|
||||
var Promise = require('bluebird');
|
||||
var createTestData = require('intern/dojo/node!../../../unit/api/index_patterns/data');
|
||||
var createTestData = require('intern/dojo/node!../../../unit/api/ingest/data');
|
||||
var _ = require('intern/dojo/node!lodash');
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
|
||||
bdd.describe('DELETE index_patterns', function deleteIndexPatterns() {
|
||||
bdd.describe('DELETE ingest', function deleteIngestConfig() {
|
||||
|
||||
bdd.beforeEach(function () {
|
||||
return scenarioManager.reload('emptyKibana')
|
||||
.then(function () {
|
||||
return request.post('/kibana/index_patterns')
|
||||
.send(createTestData().indexPattern)
|
||||
return request.post('/kibana/ingest')
|
||||
.send(createTestData())
|
||||
.expect(201);
|
||||
});
|
||||
});
|
||||
|
||||
bdd.afterEach(function () {
|
||||
return request.del('/kibana/index_patterns/logstash-*')
|
||||
return request.del('/kibana/ingest/logstash-*')
|
||||
.then(function () {
|
||||
return scenarioManager.client.indices.deleteTemplate({name: 'kibana-logstash-*'})
|
||||
.catch(function (err) {
|
||||
|
@ -31,10 +31,10 @@ define(function (require) {
|
|||
});
|
||||
|
||||
bdd.it('should return 200 for successful deletion of pattern and template', function () {
|
||||
return request.del('/kibana/index_patterns/logstash-*')
|
||||
return request.del('/kibana/ingest/logstash-*')
|
||||
.expect(200)
|
||||
.then(function () {
|
||||
return request.get('/kibana/index_patterns/logstash-*').expect(404);
|
||||
return request.get('/kibana/ingest/logstash-*').expect(404);
|
||||
})
|
||||
.then(function () {
|
||||
return scenarioManager.client.indices.getTemplate({name: 'kibana-logstash-*'})
|
||||
|
@ -45,7 +45,7 @@ define(function (require) {
|
|||
});
|
||||
|
||||
bdd.it('should return 404 for a non-existent id', function () {
|
||||
return request.del('/kibana/index_patterns/doesnotexist')
|
||||
return request.del('/kibana/ingest/doesnotexist')
|
||||
.expect(404);
|
||||
});
|
||||
|
|
@ -1,52 +1,52 @@
|
|||
define(function (require) {
|
||||
var Promise = require('bluebird');
|
||||
var createTestData = require('intern/dojo/node!../../../unit/api/index_patterns/data');
|
||||
var createTestData = require('intern/dojo/node!../../../unit/api/ingest/data');
|
||||
var _ = require('intern/dojo/node!lodash');
|
||||
var expect = require('intern/dojo/node!expect.js');
|
||||
|
||||
return function (bdd, scenarioManager, request) {
|
||||
bdd.describe('POST index_patterns', function postIndexPatterns() {
|
||||
bdd.describe('POST ingest', function postIngest() {
|
||||
|
||||
bdd.beforeEach(function () {
|
||||
return scenarioManager.reload('emptyKibana');
|
||||
});
|
||||
|
||||
bdd.afterEach(function () {
|
||||
return request.del('/kibana/index_patterns/logstash-*');
|
||||
return request.del('/kibana/ingest/logstash-*');
|
||||
});
|
||||
|
||||
bdd.it('should return 400 for an invalid payload', function invalidPayload() {
|
||||
return Promise.all([
|
||||
request.post('/kibana/index_patterns').expect(400),
|
||||
request.post('/kibana/ingest').expect(400),
|
||||
|
||||
request.post('/kibana/index_patterns')
|
||||
request.post('/kibana/ingest')
|
||||
.send({})
|
||||
.expect(400),
|
||||
|
||||
request.post('/kibana/index_patterns')
|
||||
.send(_.set(createTestData().indexPattern, 'data.attributes.title', false))
|
||||
request.post('/kibana/ingest')
|
||||
.send(_.set(createTestData(), 'title', false))
|
||||
.expect(400),
|
||||
|
||||
request.post('/kibana/index_patterns')
|
||||
.send(_.set(createTestData().indexPattern, 'data.attributes.fields', {}))
|
||||
request.post('/kibana/ingest')
|
||||
.send(_.set(createTestData(), 'fields', {}))
|
||||
.expect(400),
|
||||
|
||||
// Fields must have a name and type
|
||||
request.post('/kibana/index_patterns')
|
||||
.send(_.set(createTestData().indexPattern, 'data.attributes.fields', [{count: 0}]))
|
||||
request.post('/kibana/ingest')
|
||||
.send(_.set(createTestData(), 'fields', [{count: 0}]))
|
||||
.expect(400)
|
||||
]);
|
||||
});
|
||||
|
||||
bdd.it('should return 201 when a pattern is successfully created', function createPattern() {
|
||||
return request.post('/kibana/index_patterns')
|
||||
.send(createTestData().indexPattern)
|
||||
bdd.it('should return 201 when an ingest config is successfully created', function createIngestConfig() {
|
||||
return request.post('/kibana/ingest')
|
||||
.send(createTestData())
|
||||
.expect(201);
|
||||
});
|
||||
|
||||
bdd.it('should create an index template if a fields array is included', function createTemplate() {
|
||||
return request.post('/kibana/index_patterns')
|
||||
.send(createTestData().indexPattern)
|
||||
return request.post('/kibana/ingest')
|
||||
.send(createTestData())
|
||||
.expect(201)
|
||||
.then(function () {
|
||||
return scenarioManager.client.indices.getTemplate({name: 'kibana-logstash-*'});
|
||||
|
@ -54,8 +54,8 @@ define(function (require) {
|
|||
});
|
||||
|
||||
bdd.it('should provide defaults for field properties', function createTemplate() {
|
||||
return request.post('/kibana/index_patterns')
|
||||
.send(createTestData().indexPattern)
|
||||
return request.post('/kibana/ingest')
|
||||
.send(createTestData())
|
||||
.expect(201)
|
||||
.then(function () {
|
||||
return scenarioManager.client.get({
|
||||
|
@ -78,10 +78,10 @@ define(function (require) {
|
|||
});
|
||||
});
|
||||
|
||||
bdd.it('should create index template with _default_ mappings based on the info in the kibana index pattern',
|
||||
bdd.it('should create index template with _default_ mappings based on the info in the ingest config',
|
||||
function createTemplate() {
|
||||
return request.post('/kibana/index_patterns')
|
||||
.send(createTestData().indexPattern)
|
||||
return request.post('/kibana/ingest')
|
||||
.send(createTestData())
|
||||
.expect(201)
|
||||
.then(function () {
|
||||
return scenarioManager.client.indices.getTemplate({name: 'kibana-logstash-*'})
|
||||
|
@ -110,12 +110,12 @@ define(function (require) {
|
|||
});
|
||||
|
||||
bdd.it('should return 409 conflict when a pattern with the given ID already exists', function patternConflict() {
|
||||
return request.post('/kibana/index_patterns')
|
||||
.send(createTestData().indexPattern)
|
||||
return request.post('/kibana/ingest')
|
||||
.send(createTestData())
|
||||
.expect(201)
|
||||
.then(function () {
|
||||
return request.post('/kibana/index_patterns')
|
||||
.send(createTestData().indexPattern)
|
||||
return request.post('/kibana/ingest')
|
||||
.send(createTestData())
|
||||
.expect(409);
|
||||
});
|
||||
});
|
||||
|
@ -127,8 +127,8 @@ define(function (require) {
|
|||
template: 'logstash-*'
|
||||
}
|
||||
}).then(function () {
|
||||
return request.post('/kibana/index_patterns')
|
||||
.send(createTestData().indexPattern)
|
||||
return request.post('/kibana/ingest')
|
||||
.send(createTestData())
|
||||
.expect(409);
|
||||
})
|
||||
.then(function () {
|
||||
|
@ -140,21 +140,21 @@ define(function (require) {
|
|||
|
||||
bdd.it('should return 409 conflict when the pattern matches existing indices',
|
||||
function existingIndicesConflict() {
|
||||
var pattern = createTestData().indexPattern;
|
||||
pattern.data.id = pattern.data.attributes.title = '.kib*';
|
||||
var pattern = createTestData();
|
||||
pattern.id = pattern.title = '.kib*';
|
||||
|
||||
return request.post('/kibana/index_patterns')
|
||||
return request.post('/kibana/ingest')
|
||||
.send(pattern)
|
||||
.expect(409);
|
||||
});
|
||||
|
||||
bdd.it('should enforce snake_case in the request body', function () {
|
||||
var pattern = createTestData().indexPattern;
|
||||
pattern.data.attributes = _.mapKeys(pattern.data.attributes, function (value, key) {
|
||||
var pattern = createTestData();
|
||||
pattern = _.mapKeys(pattern, function (value, key) {
|
||||
return _.camelCase(key);
|
||||
});
|
||||
|
||||
return request.post('/kibana/index_patterns')
|
||||
return request.post('/kibana/ingest')
|
||||
.send(pattern)
|
||||
.expect(400);
|
||||
});
|
26
test/unit/api/ingest/data.js
Normal file
26
test/unit/api/ingest/data.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
module.exports = function createTestData() {
|
||||
return {
|
||||
'id': 'logstash-*',
|
||||
'title': 'logstash-*',
|
||||
'time_field_name': '@timestamp',
|
||||
'fields': [
|
||||
{
|
||||
'name': 'ip',
|
||||
'type': 'ip'
|
||||
}, {
|
||||
'name': '@timestamp',
|
||||
'type': 'date'
|
||||
}, {
|
||||
'name': 'agent',
|
||||
'type': 'string'
|
||||
}, {
|
||||
'name': 'bytes',
|
||||
'type': 'number'
|
||||
},
|
||||
{
|
||||
'name': 'geo.coordinates',
|
||||
'type': 'geo_point'
|
||||
}
|
||||
]
|
||||
};
|
||||
};
|
|
@ -9,7 +9,7 @@ define(function (require) {
|
|||
var post = require('./_post');
|
||||
var del = require('./_del');
|
||||
|
||||
bdd.describe('index_patterns API', function () {
|
||||
bdd.describe('ingest API', function () {
|
||||
var scenarioManager = new ScenarioManager(url.format(serverConfig.servers.elasticsearch));
|
||||
request = request(url.format(serverConfig.servers.kibana) + '/api');
|
||||
|
Loading…
Reference in a new issue