-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Junqiu Lei <junqiu@amazon.com>
- Loading branch information
1 parent
b7aa847
commit 7c74a3d
Showing
7 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { SavedObjectsFindResponse } from '../../../../../src/core/server'; | ||
import { MapLayerSpecification } from '../../../public/model/mapLayerType'; | ||
import { MapSavedObjectAttributes } from '../../../common/map_saved_object_attributes'; | ||
import { MAP_STATS, MAPS_STATS } from './type'; | ||
import { DASHBOARDS_MAPS_LAYER_TYPE } from '../../../common'; | ||
|
||
export const getStats = (mapsSavedObjects: SavedObjectsFindResponse<MapSavedObjectAttributes>) => { | ||
let totalLayersCount = 0; | ||
let totalDocumentsLayersCount = 0; | ||
let totalOpensearchBaseLayersCount = 0; | ||
let totalCustomTmsLayersCount = 0; | ||
let totalCustomWmsLayersCount = 0; | ||
let totalLayersFiltersCount = 0; | ||
const mapsInfo: MAP_STATS[] = []; | ||
mapsSavedObjects.saved_objects.forEach((mapRes) => { | ||
let documentsLayersCount = 0; | ||
let opensearchBaseLayersCount = 0; | ||
let customTmsLayersCount = 0; | ||
let customWmsLayersCount = 0; | ||
let layersFiltersCount = 0; | ||
const layerListJsonString = mapRes.attributes.layerList as string; | ||
const layerList: MapLayerSpecification[] = layerListJsonString | ||
? JSON.parse(layerListJsonString) | ||
: []; | ||
const layersCount = layerList.length; | ||
totalLayersCount += layerList.length; | ||
|
||
layerList.forEach((layer) => { | ||
switch (layer.type) { | ||
case DASHBOARDS_MAPS_LAYER_TYPE.DOCUMENTS: | ||
totalDocumentsLayersCount++; | ||
documentsLayersCount++; | ||
const layerFiltersCount = layer.source.filters.length; | ||
layersFiltersCount += layerFiltersCount; | ||
totalLayersFiltersCount += layerFiltersCount; | ||
break; | ||
case DASHBOARDS_MAPS_LAYER_TYPE.OPENSEARCH_MAP: | ||
totalOpensearchBaseLayersCount++; | ||
opensearchBaseLayersCount++; | ||
break; | ||
case DASHBOARDS_MAPS_LAYER_TYPE.CUSTOM_MAP: | ||
if (layer.source.customType === 'wms') { | ||
totalCustomWmsLayersCount++; | ||
customWmsLayersCount++; | ||
} else { | ||
totalCustomTmsLayersCount++; | ||
customTmsLayersCount++; | ||
} | ||
break; | ||
} | ||
}); | ||
|
||
mapsInfo.push({ | ||
id: mapRes.id, | ||
layers_filters_total: layersFiltersCount, | ||
layers_count: { | ||
total: layersCount, | ||
documents: documentsLayersCount, | ||
opensearch_base_map: opensearchBaseLayersCount, | ||
custom_tms: customTmsLayersCount, | ||
custom_wms: customWmsLayersCount, | ||
}, | ||
}); | ||
}); | ||
|
||
const metrics: MAPS_STATS = { | ||
maps_total: mapsSavedObjects.total, | ||
layers_filters_total: totalLayersFiltersCount, | ||
layers_count: { | ||
total: totalLayersCount, | ||
documents: totalDocumentsLayersCount, | ||
opensearch_base_map: totalOpensearchBaseLayersCount, | ||
custom_tms: totalCustomTmsLayersCount, | ||
custom_wms: totalCustomWmsLayersCount, | ||
}, | ||
maps: mapsInfo, | ||
}; | ||
return metrics; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export interface MAPS_STATS { | ||
maps_total: number; | ||
layers_filters_total: number; | ||
layers_count: LAYER_STATS; | ||
maps: MAP_STATS[]; | ||
} | ||
|
||
export interface MAP_STATS { | ||
id: string; | ||
layers_filters_total: number; | ||
layers_count: LAYER_STATS; | ||
} | ||
|
||
export interface LAYER_STATS { | ||
total: number; | ||
documents: number; | ||
opensearch_base_map: number; | ||
custom_tms: number; | ||
custom_wms: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { ResponseError } from '@opensearch-project/opensearch/lib/errors'; | ||
import { | ||
IOpenSearchDashboardsResponse, | ||
IRouter, | ||
SavedObjectsFindResponse, | ||
} from '../../../../src/core/server'; | ||
import { APP_API, APP_PATH, MAP_SAVED_OBJECT_TYPE } from '../../common'; | ||
import { getStats } from '../common/stats/stats_helper'; | ||
import { MapSavedObjectAttributes } from '../../common/map_saved_object_attributes'; | ||
|
||
export function statsRoute(router: IRouter) { | ||
router.get( | ||
{ | ||
path: `${APP_API}${APP_PATH.STATS}`, | ||
validate: false, | ||
}, | ||
async ( | ||
context, | ||
request, | ||
response | ||
): Promise<IOpenSearchDashboardsResponse<any | ResponseError>> => { | ||
try { | ||
const savedObjectsClient = context.core.savedObjects.client; | ||
const mapsSavedObjects: SavedObjectsFindResponse<MapSavedObjectAttributes> = | ||
await savedObjectsClient?.find({ type: MAP_SAVED_OBJECT_TYPE }); | ||
const stats = getStats(mapsSavedObjects); | ||
return response.ok({ | ||
body: stats, | ||
}); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
return response.custom({ | ||
statusCode: error.statusCode || 500, | ||
body: error.message, | ||
}); | ||
} | ||
} | ||
); | ||
} |