From d9043b49ccbac45a0e7dac1b42ee2f0fd421894c Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Thu, 24 Oct 2024 05:06:06 -0500 Subject: [PATCH] [ingest pipeline mgmt] sort list of ip location databases for consistent output (#197361) ## Summary Sort ip location database list for api output. Consistent results are testable results. Closes: https://github.com/elastic/kibana/issues/196765 (cherry picked from commit fb2452e1a129fbefe0866b734ae4111e63222cad) # Conflicts: # x-pack/test/api_integration/apis/management/ingest_pipelines/databases.ts --- .../server/routes/api/database/list.ts | 5 +++-- .../apis/management/ingest_pipelines/databases.ts | 13 ++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/ingest_pipelines/server/routes/api/database/list.ts b/x-pack/plugins/ingest_pipelines/server/routes/api/database/list.ts index b3509a5486435..eb6eb2e7dabd8 100644 --- a/x-pack/plugins/ingest_pipelines/server/routes/api/database/list.ts +++ b/x-pack/plugins/ingest_pipelines/server/routes/api/database/list.ts @@ -5,6 +5,7 @@ * 2.0. */ +import sortBy from 'lodash/sortBy'; import { deserializeGeoipDatabase, type GeoipDatabaseFromES } from './serialization'; import { API_BASE_PATH } from '../../../../common/constants'; import { RouteDependencies } from '../../../types'; @@ -21,9 +22,9 @@ export const registerListDatabaseRoute = ({ databases: GeoipDatabaseFromES[]; }; - const geoipDatabases = data.databases; + const body = sortBy(data.databases.map(deserializeGeoipDatabase), 'name'); - return res.ok({ body: geoipDatabases.map(deserializeGeoipDatabase) }); + return res.ok({ body }); } catch (error) { const esErrorResponse = handleEsError({ error, response: res }); if (esErrorResponse.status === 404) { diff --git a/x-pack/test/api_integration/apis/management/ingest_pipelines/databases.ts b/x-pack/test/api_integration/apis/management/ingest_pipelines/databases.ts index 64bab28eedb35..913e9aeca3c90 100644 --- a/x-pack/test/api_integration/apis/management/ingest_pipelines/databases.ts +++ b/x-pack/test/api_integration/apis/management/ingest_pipelines/databases.ts @@ -18,8 +18,7 @@ export default function ({ getService }: FtrProviderContext) { const ipinfoDatabaseName = 'asn'; const normalizedIpinfoDatabaseName = 'asn'; - // Failing: See https://github.com/elastic/kibana/issues/196765 - describe.skip('Manage databases', function () { + describe('Manage databases', function () { after(async () => { await ingestPipelines.api.deleteGeoipDatabases(); }); @@ -67,16 +66,16 @@ export default function ({ getService }: FtrProviderContext) { it('returns existing databases', async () => { const { body } = await supertest.get(url).set('kbn-xsrf', 'xxx').expect(200); expect(body).to.eql([ - { - id: normalizedIpinfoDatabaseName, - name: ipinfoDatabaseName, - type: 'ipinfo', - }, { id: normalizedMaxmindDatabaseName, name: maxmindDatabaseName, type: 'maxmind', }, + { + id: normalizedIpinfoDatabaseName, + name: ipinfoDatabaseName, + type: 'ipinfo', + }, ]); }); });