-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(alpha): monitoring tasks api #921
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6fb52b4
feat(alpha): monitoring tasks api
polomani 2fc9e19
chore: update docs in the readme
polomani aa0a51f
test: improve integration tests
polomani c6277b0
chore: add copy
polomani e1d646b
docs: update readme
polomani 3000220
test: skip geospatial integration tests
polomani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
114 changes: 114 additions & 0 deletions
114
packages/alpha/src/__tests__/api/monitoringTasksApi.int.spec.ts
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,114 @@ | ||
// Copyright 2022 Cognite AS | ||
|
||
import { Channel } from 'alpha/src/types'; | ||
import CogniteClientAlpha from '../../cogniteClient'; | ||
import { | ||
CLIENT_ID, | ||
CLIENT_SECRET, | ||
setupLoggedInClient, | ||
TEST_PROJECT, | ||
} from '../testUtils'; | ||
|
||
type SessionsResponse = { | ||
items: [{ nonce: string; status: string }]; | ||
}; | ||
|
||
const itif = (condition: any) => (condition ? it : it.skip); | ||
|
||
describe('monitoring tasks api', () => { | ||
const client: CogniteClientAlpha | null = setupLoggedInClient(); | ||
const ts = Date.now(); | ||
const monitoringTaskExternalId = `test_mt_${ts}`; | ||
const channelExternalId = `test_channel_mt_${ts}`; | ||
const sessionsApi = `/api/v1/projects/${TEST_PROJECT}/sessions`; | ||
const testMtParams = { | ||
threshold: 50.1, | ||
timeseriesExternalId: 'test_functions', | ||
granularity: '1m', | ||
}; | ||
const testMtOverlap = 1000 * 60; | ||
const testMtInterval = 5 * 60 * 1000; | ||
const testMtModelExternalId = 'air-upper-threshold'; | ||
let channel: Channel; | ||
|
||
itif(client)('create monitoring task', async () => { | ||
const sessionsRes = await client!.post<SessionsResponse>(sessionsApi, { | ||
data: { | ||
items: [ | ||
{ | ||
clientId: CLIENT_ID, | ||
clientSecret: CLIENT_SECRET, | ||
}, | ||
], | ||
}, | ||
}); | ||
const res = await client!.alerts.createChannels([ | ||
{ | ||
externalId: channelExternalId, | ||
name: channelExternalId, | ||
description: 'test', | ||
}, | ||
]); | ||
channel = res[0]; | ||
expect(channel).toBeTruthy(); | ||
const response = await client!.monitoringTasks.create([ | ||
{ | ||
externalId: monitoringTaskExternalId, | ||
channelId: channel.id, | ||
interval: testMtInterval, | ||
nonce: sessionsRes?.data?.items[0]?.nonce, | ||
modelExternalId: testMtModelExternalId, | ||
overlap: testMtOverlap, | ||
parameters: testMtParams, | ||
}, | ||
]); | ||
expect(response.length).toBe(1); | ||
expect(response[0].externalId).toBe(monitoringTaskExternalId); | ||
}); | ||
|
||
itif(client)('list all monitoring tasks', async () => { | ||
const response = await client!.monitoringTasks.list({ | ||
filter: {}, | ||
}); | ||
expect(response.items.length).toBeGreaterThan(0); | ||
}); | ||
|
||
itif(client)('list created monitoring task', async () => { | ||
const response = await client!.monitoringTasks.list({ | ||
filter: { externalIds: [monitoringTaskExternalId] }, | ||
}); | ||
expect(response.items.length).toBe(1); | ||
expect(response.items[0].externalId).toEqual(monitoringTaskExternalId); | ||
expect(response.items[0].parameters).toEqual(testMtParams); | ||
expect(response.items[0].interval).toEqual(testMtInterval); | ||
expect(response.items[0].overlap).toEqual(testMtOverlap); | ||
expect(response.items[0].modelExternalId).toEqual(testMtModelExternalId); | ||
}); | ||
|
||
itif(client)('list created monitoring task by channel', async () => { | ||
const response = await client!.monitoringTasks.list({ | ||
filter: { channelIds: [channel.id] }, | ||
}); | ||
expect(response.items.length).toBe(1); | ||
expect(response.items[0].externalId).toEqual(monitoringTaskExternalId); | ||
expect(response.items[0].channelId).toEqual(channel.id); | ||
}); | ||
|
||
itif(client)('delete monitoring task', async () => { | ||
const response = await client!.monitoringTasks.delete([ | ||
{ | ||
externalId: monitoringTaskExternalId, | ||
}, | ||
]); | ||
expect(response).toEqual({}); | ||
}); | ||
|
||
itif(client)('delete channel', async () => { | ||
const response = await client!.alerts.deleteChannels([ | ||
{ | ||
externalId: channelExternalId, | ||
}, | ||
]); | ||
expect(response).toEqual({}); | ||
}); | ||
}); |
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
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
25 changes: 25 additions & 0 deletions
25
packages/alpha/src/api/monitoringTasks/monitoringTasksApi.ts
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 2022 Cognite AS | ||
|
||
import { BaseResourceAPI, IdEither } from '@cognite/sdk-core'; | ||
import { | ||
MonitoringTask, | ||
MonitoringTaskCreate, | ||
MonitoringTaskFilterQuery, | ||
} from '../../types'; | ||
|
||
export class MonitoringTasksAPI extends BaseResourceAPI<MonitoringTask> { | ||
public create = async (items: MonitoringTaskCreate[]) => { | ||
return this.createEndpoint(items); | ||
}; | ||
|
||
public list = async (filter?: MonitoringTaskFilterQuery) => { | ||
return this.listEndpoint<MonitoringTaskFilterQuery>( | ||
this.callListEndpointWithPost, | ||
filter | ||
); | ||
}; | ||
|
||
public delete = async (ids: IdEither[]) => { | ||
return this.deleteEndpoint(ids); | ||
}; | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check for status 200?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we technically don't have access to the status at this level anymore (at least the easy way), if 400+ status happens it will throw an error at earlier stages