From 923f785ec0ecfdee1f2b8344a0c316c96dcfa974 Mon Sep 17 00:00:00 2001 From: jrea Date: Tue, 13 Sep 2022 16:13:32 -0400 Subject: [PATCH] feat: add metrics methods to nile --- lib/nile/spec/api.yaml | 153 +++++++++++++++++++++++++++++++- lib/nile/src/Nile.ts | 12 ++- lib/nile/src/test/index.test.ts | 9 ++ 3 files changed, 172 insertions(+), 2 deletions(-) diff --git a/lib/nile/spec/api.yaml b/lib/nile/spec/api.yaml index f5665c03..0a9c4475 100644 --- a/lib/nile/spec/api.yaml +++ b/lib/nile/spec/api.yaml @@ -4,7 +4,7 @@ info: description: Making SaaS chill. contact: email: support@thenile.dev - version: 0.1-296b8c8 + version: 0.1-f7863eb servers: - url: localhost:8080 paths: @@ -705,6 +705,67 @@ paths: type: array items: $ref: '#/components/schemas/Invite' + /workspaces/{workspace}/metrics/filter: + post: + tags: + - metrics + summary: List of metrics matching the filter + operationId: filterMetrics + parameters: + - $ref: '#/components/parameters/workspace' + - name: from_timestamp + in: query + schema: + type: string + description: "The ISO-8601 formatted timestamp used to begin searching for\ + \ matching metrics, i.e., 2018-11-13T20:20:39+00:00. If not provided the\ + \ range will start from the epoch. Results returned are inclusive of this\ + \ timestamp." + format: date-time + - name: duration + in: query + schema: + type: integer + description: "The duration (seconds) added to from_timestamp to limit the\ + \ time range of the query. i.e., the query will be restricting to metric.timestamp\ + \ >= from_timestamp AND metric.timestamp < from_timestamp + duration.\ + \ If not provided or the duration is <=0 then the end timestamp is set\ + \ to now" + format: int32 + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Filter' + required: true + responses: + "200": + description: A list of metrics that match the filter + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Metric' + /workspaces/{workspace}/metrics: + post: + tags: + - metrics + summary: Produce a Batch of Metrics + operationId: produceBatchOfMetrics + parameters: + - $ref: '#/components/parameters/workspace' + requestBody: + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Metric' + required: true + responses: + "204": + description: the metrics have been saved /workspaces/{workspace}/orgs/{org}/users: get: tags: @@ -1045,6 +1106,35 @@ paths: application/json: schema: $ref: '#/components/schemas/Workspace' + /workspaces/{workspace}/openapi: + get: + tags: + - workspaces + summary: Get the OpenAPI specification for all events and entities in this workspace + operationId: getWorkspaceOpenApi + parameters: + - name: workspace + in: path + required: true + schema: + type: string + responses: + "200": + description: The yaml OpenAPI specification for all events and entities + in this workspace + content: + application/yaml: + schema: + type: string + application/json: + schema: + type: string + "401": + description: The current user is not authorized to access this resource + content: + application/json: + schema: + $ref: '#/components/schemas/Error' components: schemas: Action: @@ -1460,6 +1550,67 @@ components: type: string enum: - active + Measurement: + required: + - instance_id + - timestamp + - value + type: object + properties: + timestamp: + type: string + description: An ISO-8601 formatted date-time https://www.iso.org/iso-8601-date-and-time-format.html + that represents the time the datapoint was created + format: date-time + value: + type: number + description: the measured value + format: double + instance_id: + type: string + description: InstanceId of the Nile instance this datapoint is related to + attributes: + type: object + additionalProperties: + type: object + description: Measurements associated with this metric + Metric: + required: + - entityType + - measurements + - name + - type + type: object + properties: + name: + type: string + description: The name of the metric that is unique in a workspace + type: + type: string + description: Type of metric. Currently sum or gauge + enum: + - gauge + - sum + entityType: + type: string + description: The Nile entity type this metric is related to + measurements: + type: array + description: Measurements associated with this metric + items: + $ref: '#/components/schemas/Measurement' + Filter: + type: object + properties: + metric_name: + type: string + description: Name of the metric to filter on + instance_id: + type: string + description: The Nile instance id to filter on + entity_type: + type: string + description: The Nile entity type to filter on AddUserToOrgRequest: required: - email diff --git a/lib/nile/src/Nile.ts b/lib/nile/src/Nile.ts index 1f6271da..ad331577 100644 --- a/lib/nile/src/Nile.ts +++ b/lib/nile/src/Nile.ts @@ -9,6 +9,7 @@ import { OrganizationsApi, UsersApi, WorkspacesApi, + MetricsApi, } from './generated/openapi/src'; import { Configuration, @@ -25,7 +26,7 @@ export class NileApi { organizations: OrganizationsApi; events: EventsApi; access: AccessApi; - + metrics: MetricsApi; constructor(configuration?: Configuration) { this.users = new UsersApi(configuration); this.developers = new DevelopersApi(configuration); @@ -34,6 +35,7 @@ export class NileApi { this.organizations = new OrganizationsApi(configuration); this.events = new EventsApi(this.entities); this.access = new AccessApi(configuration); + this.metrics = new MetricsApi(configuration); } set workspace(workspace: void | string) { @@ -44,6 +46,7 @@ export class NileApi { this.workspaces.workspace = workspace; this.organizations.workspace = workspace; this.access.workspace = workspace; + this.metrics.workspace = workspace; } } @@ -66,6 +69,9 @@ export class NileApi { if (this.access.workspace) { return this.access.workspace; } + if (this.metrics.workspace) { + return this.metrics.workspace; + } } set authToken(token: void | string) { @@ -76,6 +82,7 @@ export class NileApi { this.workspaces.authToken = token; this.organizations.authToken = token; this.access.authToken = token; + this.metrics.authToken = token; } } @@ -98,6 +105,9 @@ export class NileApi { if (this.access.authToken) { return this.access.authToken; } + if (this.metrics.authToken) { + return this.metrics.authToken; + } } /** * Creates a NileApi instance and connects using the provided credentials. diff --git a/lib/nile/src/test/index.test.ts b/lib/nile/src/test/index.test.ts index f98e54d9..42f72c49 100644 --- a/lib/nile/src/test/index.test.ts +++ b/lib/nile/src/test/index.test.ts @@ -19,6 +19,7 @@ describe('index', () => { 'organizations', 'events', 'access', + 'metrics', ]); keys.forEach((k) => { const props = Object.getOwnPropertyNames( @@ -29,6 +30,7 @@ describe('index', () => { expect(props).toEqual([ 'constructor', 'createWorkspace', + 'getWorkspaceOpenApi', 'listWorkspaces', ]); } @@ -98,6 +100,13 @@ describe('index', () => { 'updatePolicy', ]); } + if (k === 'metrics') { + expect(props).toEqual([ + 'constructor', + 'filterMetrics', + 'produceBatchOfMetrics', + ]); + } }); });