feat(compute resources): suggest recommended limits to CPU and Memory for a Function (#243)

* feat(compute resources): suggest recommended limits to CPU and Memory for a Function

* Adds documentation
This commit is contained in:
Iain Sproat
2023-11-06 13:48:11 +00:00
committed by GitHub
parent 2cf7d93b74
commit 2f4e3cf8e3
6 changed files with 85 additions and 19 deletions
+12
View File
@@ -45,6 +45,18 @@ Providing a Speckle Function ID allows you to change one of those values, and up
Your Speckle Token must have write permissions for the Speckle Function with this ID, otherwise the publish will fail.
#### `speckle_function_recommended_cpu_m`
*Optional.* The recommended maximum CPU in millicores for the function. If the Function exceeds this limit, it will be throttled to run within the limit.
1000 millicores = 1 CPU core. Defaults to 1000 millicores (1 CPU core).
#### `speckle_function_recommended_memory_mi`
*Optional.* The recommended maximum memory in mebibytes for the function. If the Function exceeds this limit, it will be **terminated**.
1024 mebibytes = 1 gibibyte. Defaults to 100 mebibytes.
### Outputs
#### `version_id`
+6
View File
@@ -24,6 +24,12 @@ inputs:
speckle_function_release_tag:
description: 'User defined tag for the function release'
required: true
speckle_function_recommended_cpu_m:
description: 'The recommended maximum CPU in millicores for the function. 1000 millicores = 1 CPU core. Defaults to 1000 millicores (1 CPU core). If the Function exceeds this limit, it will be throttled to run within the limit.'
required: false
speckle_function_recommended_memory_mi:
description: 'The recommended maximum memory in mebibytes for the function. 1024 mebibytes = 1 gibibyte. Defaults to 100 mebibytes. If the Function exceeds this limit, it will be terminated.'
required: false
outputs:
speckle_automate_function_release_id:
description: 'The unique identifier of the function release.'
Generated Vendored
+27 -9
View File
@@ -14090,12 +14090,24 @@ var external_node_path_ = __nccwpck_require__(9411);
const InputVariablesSchema = z.object({
speckleAutomateUrl: z.string().url().nonempty(),
speckleToken: z.string().nonempty(),
speckleFunctionId: z.string().nonempty(),
speckleAutomateUrl: z.string().url().min(1),
speckleToken: z.string().min(1),
speckleFunctionId: z.string().min(1),
speckleFunctionInputSchema: z.record(z.string().nonempty(), z.unknown()).nullable(),
speckleFunctionCommand: z.string().nonempty().array(),
speckleFunctionReleaseTag: z.string().max(10).nonempty()
speckleFunctionCommand: z.string().min(1).array(),
speckleFunctionReleaseTag: z.string().max(10).min(1),
speckleFunctionRecommendedCPUm: z.number()
.int()
.finite()
.gte(100)
.lte(16000)
.optional(),
speckleFunctionRecommendedMemoryMi: z.number()
.int()
.finite()
.gte(1)
.lte(8000)
.optional()
});
const parseInputs = () => {
const speckleTokenRaw = core.getInput('speckle_token', { required: true });
@@ -14118,7 +14130,11 @@ const parseInputs = () => {
.split(' '),
speckleFunctionReleaseTag: core.getInput('speckle_function_release_tag', {
required: true
})
}),
speckleFunctionRecommendedCPUm: parseInt(core.getInput('speckle_function_recommended_cpu_m', {
required: false
})),
speckleFunctionRecommendedMemoryMi: parseInt(core.getInput('speckle_function_recommended_memory_mi', { required: false }))
};
const inputParseResult = InputVariablesSchema.safeParse(rawInputs);
if (inputParseResult.success)
@@ -14139,7 +14155,7 @@ const parseEnvVars = () => {
const FunctionVersionResponseBodySchema = z.object({
versionId: z.string().nonempty()
});
const registerNewVersionForTheSpeckleAutomateFunction = async ({ speckleAutomateUrl, speckleFunctionCommand, speckleFunctionId, speckleFunctionInputSchema, speckleToken, speckleFunctionReleaseTag }, commitId
const registerNewVersionForTheSpeckleAutomateFunction = async ({ speckleAutomateUrl, speckleFunctionCommand, speckleFunctionId, speckleFunctionInputSchema, speckleToken, speckleFunctionReleaseTag, speckleFunctionRecommendedCPUm, speckleFunctionRecommendedMemoryMi }, commitId
// { gitCommitSha, gitRefName, gitRefType }: RequiredEnvVars
) => {
try {
@@ -14147,7 +14163,9 @@ const registerNewVersionForTheSpeckleAutomateFunction = async ({ speckleAutomate
commitId,
versionTag: speckleFunctionReleaseTag,
command: speckleFunctionCommand,
inputSchema: speckleFunctionInputSchema
inputSchema: speckleFunctionInputSchema,
recommendedCPUm: speckleFunctionRecommendedCPUm,
recommendedMemoryMi: speckleFunctionRecommendedMemoryMi
};
const versionRegisterUrl = new URL(`/api/v1/functions/${speckleFunctionId}/versions`, speckleAutomateUrl);
const retryFlag = 'RETRY THIS';
@@ -14232,7 +14250,7 @@ async function run() {
catch (e) {
return failAndReject(e, 'Failed to register the new function version');
}
core.info(`Registered function version tagged as ${inputVariables.speckleFunctionReleaseTag} with new id: ${versionId}`);
core.info(`Registered function version tagged as ${inputVariables.speckleFunctionReleaseTag} with new id: ${versionId}. Recommended CPU: ${inputVariables.speckleFunctionRecommendedCPUm}m, recommended memory: ${inputVariables.speckleFunctionRecommendedMemoryMi}Mi.`);
core.setOutput('speckle_automate_function_release_id', versionId);
}
run();
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+37 -9
View File
@@ -6,12 +6,26 @@ import { readFileSync } from 'node:fs'
import { join } from 'node:path'
const InputVariablesSchema = z.object({
speckleAutomateUrl: z.string().url().nonempty(),
speckleToken: z.string().nonempty(),
speckleFunctionId: z.string().nonempty(),
speckleAutomateUrl: z.string().url().min(1),
speckleToken: z.string().min(1),
speckleFunctionId: z.string().min(1),
speckleFunctionInputSchema: z.record(z.string().nonempty(), z.unknown()).nullable(),
speckleFunctionCommand: z.string().nonempty().array(),
speckleFunctionReleaseTag: z.string().max(10).nonempty()
speckleFunctionCommand: z.string().min(1).array(),
speckleFunctionReleaseTag: z.string().max(10).min(1),
speckleFunctionRecommendedCPUm: z
.number()
.int()
.finite()
.gte(100)
.lte(16000)
.optional(),
speckleFunctionRecommendedMemoryMi: z
.number()
.int()
.finite()
.gte(1)
.lte(8000)
.optional()
})
type InputVariables = z.infer<typeof InputVariablesSchema>
@@ -40,7 +54,15 @@ const parseInputs = (): InputVariables => {
.split(' '),
speckleFunctionReleaseTag: core.getInput('speckle_function_release_tag', {
required: true
})
}),
speckleFunctionRecommendedCPUm: parseInt(
core.getInput('speckle_function_recommended_cpu_m', {
required: false
})
),
speckleFunctionRecommendedMemoryMi: parseInt(
core.getInput('speckle_function_recommended_memory_mi', { required: false })
)
}
const inputParseResult = InputVariablesSchema.safeParse(rawInputs)
if (inputParseResult.success) return inputParseResult.data
@@ -66,6 +88,8 @@ type FunctionVersionRequestBody = {
versionTag: string
command: string[]
inputSchema: Record<string, unknown> | null
recommendedCPUm?: number
recommendedMemoryMi?: number
}
const FunctionVersionResponseBodySchema = z.object({
@@ -81,7 +105,9 @@ const registerNewVersionForTheSpeckleAutomateFunction = async (
speckleFunctionId,
speckleFunctionInputSchema,
speckleToken,
speckleFunctionReleaseTag
speckleFunctionReleaseTag,
speckleFunctionRecommendedCPUm,
speckleFunctionRecommendedMemoryMi
}: InputVariables,
commitId: string
// { gitCommitSha, gitRefName, gitRefType }: RequiredEnvVars
@@ -91,7 +117,9 @@ const registerNewVersionForTheSpeckleAutomateFunction = async (
commitId,
versionTag: speckleFunctionReleaseTag,
command: speckleFunctionCommand,
inputSchema: speckleFunctionInputSchema
inputSchema: speckleFunctionInputSchema,
recommendedCPUm: speckleFunctionRecommendedCPUm,
recommendedMemoryMi: speckleFunctionRecommendedMemoryMi
}
const versionRegisterUrl = new URL(
`/api/v1/functions/${speckleFunctionId}/versions`,
@@ -197,7 +225,7 @@ export async function run(): Promise<void> {
return failAndReject(e, 'Failed to register the new function version')
}
core.info(
`Registered function version tagged as ${inputVariables.speckleFunctionReleaseTag} with new id: ${versionId}`
`Registered function version tagged as ${inputVariables.speckleFunctionReleaseTag} with new id: ${versionId}. Recommended CPU: ${inputVariables.speckleFunctionRecommendedCPUm}m, recommended memory: ${inputVariables.speckleFunctionRecommendedMemoryMi}Mi.`
)
core.setOutput('speckle_automate_function_release_id', versionId)
}
+2
View File
@@ -72,6 +72,8 @@ describe('Register new version', () => {
vi.stubEnv('HOME', tmpDir) // the input schema file path is assumed to be relative to the home directory
vi.stubEnv('INPUT_SPECKLE_FUNCTION_INPUT_SCHEMA_FILE_PATH', './schema.json')
vi.stubEnv('INPUT_SPECKLE_FUNCTION_RELEASE_TAG', 'v1.0.0')
vi.stubEnv('INPUT_SPECKLE_FUNCTION_RECOMMENDED_CPU_M', '1000')
vi.stubEnv('INPUT_SPECKLE_FUNCTION_RECOMMENDED_MEMORY_MI', '500')
vi.stubEnv('INPUT_SPECKLE_AUTOMATE_URL', 'http://myfakeautomate.speckle.internal')
vi.stubEnv('GITHUB_SHA', 'commitSha')
vi.stubEnv('GITHUB_REF_TYPE', 'commit')