import { StartServicesAccessor , IRouter , Logger } from 'opensearch-dashboards/server' ; import { schema } from '@osd/config-schema' ; export function registerDqlTelemetryRoute ( router , getStartServices , logger ) { router . post ( { path : '/api/opensearch-dashboards/dql_opt_in_stats' , validate : { body : schema . object ( { opt_in : schema . boolean ( ) , } ) , } , } , async ( context , request , response ) => { const [ { savedObjects } ] = await getStartServices ( ) ; const internalRepository = savedObjects . createScopedRepository ( request ) ; const { body : { opt_in : optIn } , } = request ; const counterName = optIn ? 'optInCount' : 'optOutCount' ; try { await internalRepository . incrementCounter ( 'dql-telemetry' , 'dql-telemetry' , counterName ) ; } catch ( error ) { logger . warn ( `Unable to increment counter: ${ error }` ) ; return response . customError ( { statusCode : error . status , body : { message : 'Something went wrong' , attributes : { success : false , } , } , } ) ; } return response . ok ( { body : { success : true } } ) ; } ) ; }