mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	Turns out we've been trying to return API token data in instance stats for a while, but that the serialization has failed. Serializing a JS map just yields an empty object. This PR fixes that serialization and also adds API tokens to the instance stats schema (it wasn't before, but we did return it). Adding it to the schema is also part of making resource usage visible as part of the soft limits project.
		
			
				
	
	
		
			261 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			261 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import type { FromSchema } from 'json-schema-to-ts';
 | |
| 
 | |
| export const instanceAdminStatsSchema = {
 | |
|     $id: '#/components/schemas/instanceAdminStatsSchema',
 | |
|     type: 'object',
 | |
|     additionalProperties: false,
 | |
|     description:
 | |
|         'Information about an instance and statistics about usage of various features of Unleash',
 | |
|     required: ['instanceId'],
 | |
|     properties: {
 | |
|         instanceId: {
 | |
|             type: 'string',
 | |
|             description:
 | |
|                 'A unique identifier for this instance. Generated by the database migration scripts at first run. Typically a UUID.',
 | |
|             example: 'ed3861ae-78f9-4e8c-8e57-b57efc15f82b',
 | |
|         },
 | |
|         timestamp: {
 | |
|             type: 'string',
 | |
|             format: 'date-time',
 | |
|             nullable: true,
 | |
|             description: 'When these statistics were produced',
 | |
|             example: '2023-06-12T12:25:06Z',
 | |
|         },
 | |
|         versionOSS: {
 | |
|             type: 'string',
 | |
|             description:
 | |
|                 'The version of Unleash OSS that is bundled in this instance',
 | |
|             example: '5.1.7',
 | |
|         },
 | |
|         versionEnterprise: {
 | |
|             type: 'string',
 | |
|             description:
 | |
|                 'The version of Unleash Enterprise that is bundled in this instance',
 | |
|             example: '5.1.7',
 | |
|         },
 | |
|         users: {
 | |
|             type: 'number',
 | |
|             description: 'The number of users this instance has',
 | |
|             example: 8,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         previousDayMetricsBucketsCount: {
 | |
|             type: 'object',
 | |
|             description:
 | |
|                 'The number client metrics buckets records recorded in the previous day. # features * # apps * # envs * # hours with metrics',
 | |
|             properties: {
 | |
|                 enabledCount: {
 | |
|                     type: 'number',
 | |
|                     description:
 | |
|                         'The number of enabled/disabled metrics buckets recorded in the previous day',
 | |
|                     example: 10,
 | |
|                     minimum: 0,
 | |
|                 },
 | |
|                 variantCount: {
 | |
|                     type: 'number',
 | |
|                     description:
 | |
|                         'The number of variant metrics buckets recorded in the previous day',
 | |
|                     example: 10,
 | |
|                     minimum: 0,
 | |
|                 },
 | |
|             },
 | |
|         },
 | |
|         activeUsers: {
 | |
|             type: 'object',
 | |
|             description:
 | |
|                 'The number of active users in the last 7, 30 and 90 days',
 | |
|             properties: {
 | |
|                 last7: {
 | |
|                     type: 'number',
 | |
|                     description:
 | |
|                         'The number of active users in the last 7 days',
 | |
|                     example: 5,
 | |
|                     minimum: 0,
 | |
|                 },
 | |
|                 last30: {
 | |
|                     type: 'number',
 | |
|                     description:
 | |
|                         'The number of active users in the last 30 days',
 | |
|                     example: 10,
 | |
|                     minimum: 0,
 | |
|                 },
 | |
|                 last60: {
 | |
|                     type: 'number',
 | |
|                     description:
 | |
|                         'The number of active users in the last 60 days',
 | |
|                     example: 12,
 | |
|                     minimum: 0,
 | |
|                 },
 | |
|                 last90: {
 | |
|                     type: 'number',
 | |
|                     description:
 | |
|                         'The number of active users in the last 90 days',
 | |
|                     example: 15,
 | |
|                     minimum: 0,
 | |
|                 },
 | |
|             },
 | |
|         },
 | |
|         productionChanges: {
 | |
|             type: 'object',
 | |
|             description:
 | |
|                 'The number of changes to the production environment in the last 30, 60 and 90 days',
 | |
|             properties: {
 | |
|                 last30: {
 | |
|                     type: 'number',
 | |
|                     description:
 | |
|                         'The number of changes in production in the last 30 days',
 | |
|                     example: 10,
 | |
|                     minimum: 0,
 | |
|                 },
 | |
|                 last60: {
 | |
|                     type: 'number',
 | |
|                     description:
 | |
|                         'The number of changes in production in the last 60 days',
 | |
|                     example: 12,
 | |
|                     minimum: 0,
 | |
|                 },
 | |
|                 last90: {
 | |
|                     type: 'number',
 | |
|                     description:
 | |
|                         'The number of changes in production in the last 90 days',
 | |
|                     example: 15,
 | |
|                     minimum: 0,
 | |
|                 },
 | |
|             },
 | |
|         },
 | |
|         featureToggles: {
 | |
|             type: 'number',
 | |
|             description: 'The number of feature-toggles this instance has',
 | |
|             example: 47,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         projects: {
 | |
|             type: 'number',
 | |
|             description: 'The number of projects defined in this instance.',
 | |
|             example: 3,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         contextFields: {
 | |
|             type: 'number',
 | |
|             description:
 | |
|                 'The number of context fields defined in this instance.',
 | |
|             example: 7,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         roles: {
 | |
|             type: 'number',
 | |
|             description: 'The number of roles defined in this instance',
 | |
|             example: 5,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         groups: {
 | |
|             type: 'number',
 | |
|             description: 'The number of groups defined in this instance',
 | |
|             example: 12,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         environments: {
 | |
|             type: 'number',
 | |
|             description: 'The number of environments defined in this instance',
 | |
|             example: 3,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         segments: {
 | |
|             type: 'number',
 | |
|             description: 'The number of segments defined in this instance',
 | |
|             example: 19,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         strategies: {
 | |
|             type: 'number',
 | |
|             description: 'The number of strategies defined in this instance',
 | |
|             example: 8,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         SAMLenabled: {
 | |
|             type: 'boolean',
 | |
|             description:
 | |
|                 'Whether or not SAML authentication is enabled for this instance',
 | |
|             example: false,
 | |
|         },
 | |
|         OIDCenabled: {
 | |
|             type: 'boolean',
 | |
|             description:
 | |
|                 'Whether or not OIDC authentication is enabled for this instance',
 | |
|             example: true,
 | |
|         },
 | |
|         clientApps: {
 | |
|             type: 'array',
 | |
|             description:
 | |
|                 'A count of connected applications in the last week, last month and all time since last restart',
 | |
|             items: {
 | |
|                 type: 'object',
 | |
|                 description:
 | |
|                     'An entry describing how many client applications has been observed over the defined range',
 | |
|                 properties: {
 | |
|                     range: {
 | |
|                         type: 'string',
 | |
|                         description: 'A description of a time range',
 | |
|                         enum: ['allTime', '30d', '7d'],
 | |
|                         example: '30d',
 | |
|                     },
 | |
|                     count: {
 | |
|                         type: 'number',
 | |
|                         description:
 | |
|                             'The number of client applications that have been observed in this period',
 | |
|                         example: 1,
 | |
|                     },
 | |
|                 },
 | |
|             },
 | |
|         },
 | |
|         featureExports: {
 | |
|             type: 'number',
 | |
|             description: 'The number of export operations on this instance',
 | |
|             example: 0,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         featureImports: {
 | |
|             type: 'number',
 | |
|             description: 'The number of import operations on this instance',
 | |
|             example: 0,
 | |
|             minimum: 0,
 | |
|         },
 | |
|         apiTokens: {
 | |
|             type: 'object',
 | |
|             description: 'The number of API tokens in Unleash, split by type',
 | |
|             properties: {
 | |
|                 admin: {
 | |
|                     type: 'number',
 | |
|                     description: 'The number of admin tokens.',
 | |
|                     minimum: 0,
 | |
|                     example: 5,
 | |
|                 },
 | |
|                 client: {
 | |
|                     type: 'number',
 | |
|                     description: 'The number of client tokens.',
 | |
|                     minimum: 0,
 | |
|                     example: 5,
 | |
|                 },
 | |
|                 frontend: {
 | |
|                     type: 'number',
 | |
|                     description: 'The number of frontend tokens.',
 | |
|                     minimum: 0,
 | |
|                     example: 5,
 | |
|                 },
 | |
|             },
 | |
|         },
 | |
|         sum: {
 | |
|             type: 'string',
 | |
|             description:
 | |
|                 'A SHA-256 checksum of the instance statistics to be used to verify that the data in this object has not been tampered with',
 | |
|             example:
 | |
|                 'b023323477abb1eb145bebf3cdb30a1c2063e3edc1f7ae474ed8ed6c80de9a3b',
 | |
|         },
 | |
|     },
 | |
|     components: {},
 | |
| } as const;
 | |
| 
 | |
| export type InstanceAdminStatsSchema = FromSchema<
 | |
|     typeof instanceAdminStatsSchema
 | |
| >;
 |