Skip to content

Commit

Permalink
feat: add metrics methods to nile
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed Sep 16, 2022
1 parent 0c38d4c commit 923f785
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 2 deletions.
153 changes: 152 additions & 1 deletion lib/nile/spec/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ info:
description: Making SaaS chill.
contact:
email: [email protected]
version: 0.1-296b8c8
version: 0.1-f7863eb
servers:
- url: localhost:8080
paths:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion lib/nile/src/Nile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
OrganizationsApi,
UsersApi,
WorkspacesApi,
MetricsApi,
} from './generated/openapi/src';
import {
Configuration,
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -44,6 +46,7 @@ export class NileApi {
this.workspaces.workspace = workspace;
this.organizations.workspace = workspace;
this.access.workspace = workspace;
this.metrics.workspace = workspace;
}
}

Expand All @@ -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) {
Expand All @@ -76,6 +82,7 @@ export class NileApi {
this.workspaces.authToken = token;
this.organizations.authToken = token;
this.access.authToken = token;
this.metrics.authToken = token;
}
}

Expand All @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions lib/nile/src/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('index', () => {
'organizations',
'events',
'access',
'metrics',
]);
keys.forEach((k) => {
const props = Object.getOwnPropertyNames(
Expand All @@ -29,6 +30,7 @@ describe('index', () => {
expect(props).toEqual([
'constructor',
'createWorkspace',
'getWorkspaceOpenApi',
'listWorkspaces',
]);
}
Expand Down Expand Up @@ -98,6 +100,13 @@ describe('index', () => {
'updatePolicy',
]);
}
if (k === 'metrics') {
expect(props).toEqual([
'constructor',
'filterMetrics',
'produceBatchOfMetrics',
]);
}
});
});

Expand Down

0 comments on commit 923f785

Please sign in to comment.