From ec98844e7d6b164805401953e31fbec8bfa30d0a Mon Sep 17 00:00:00 2001 From: Gnanakeethan Balasubramaniam Date: Thu, 12 Oct 2023 12:52:40 +0530 Subject: [PATCH] Add documentation and fixes for test Signed-off-by: Gnanakeethan Balasubramaniam --- .../cloud-instance-metadata.md | 89 +++++++++++++++++++ src/lib/cloud-instance-metadata/index.test.ts | 10 +-- 2 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 docs/implementations/cloud-instance-metadata.md diff --git a/docs/implementations/cloud-instance-metadata.md b/docs/implementations/cloud-instance-metadata.md new file mode 100644 index 000000000..2430b574d --- /dev/null +++ b/docs/implementations/cloud-instance-metadata.md @@ -0,0 +1,89 @@ +# Cloud Instance Metadata + +This plugin allows you to determine an instance's CPU based on its instance name. + +## IEF Implementation + +IEF implements this plugin using data from Cloud Carbon Footprint. This allows determination of cpu for type of instance in a cloud and can be invoked as part of a model pipeline defined in an `impl`. + +Cloud Instance Metadata currently implements only for 'AWS'. + +## Usage + +In IEF, the model is called from an `impl`. An `impl` is a `.yaml` file that contains configuration metadata and usage observations. This is interpreted by the command line tool, `rimpl`. There, the model's `configure` method is called first. The model config shall be empty. Each observation is expected to contain `cloud-vendor` and `cloud-instance-type` fields. + +You can see example Typescript invocations for each provider below: + +### AWS + +```typescript +import {CloudInstanceMetadataModel} from 'ief'; + +const cimm = new CloudInstanceMetadataModel(); +const results = cimm.calculate([ + { + 'cloud-vendor': 'aws', + 'cloud-instance-type': 'm5n.large' + } +]) +``` + +## Example Impl + +The following is an example of how cloud instance metadata can be invoked using an `impl`. + +```yaml +name: cloud-instance-metadata-demo +description: example impl invoking Cloud Instance Metadata model +initialize: + models: + - name: cloud-instance-metadata + kind: builtin +graph: + children: + child: + pipeline: + - cloud-instance-metadata + config: + observations: + - timestamp: 2023-07-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred + provider: aws + instance_type: m5n.large + duration: 100 + cpu-util: 10 +``` + +This impl is run using `rimpl` using the following command, run from the project root: + +```sh +npx ts-node scripts/rimpl.ts --impl ./examples/impls/cimd-test.yml --ompl ./examples/ompls/cimd-test.yml +``` + +This yields a result that looks like the following (saved to `/ompls/cimd-test.yml`): + +```yaml +name: cloud-instance-metadata-demo +description: example impl invoking Cloud Instance Metadata model +initialize: + models: + - name: cloud-instance-metadata + kind: builtin +graph: + children: + front-end: + pipeline: + - cloud-instance-metadata + observations: + - timestamp: 2023-07-06T00:00 + cloud-vendor: aws + cloud-instance-type: m5n.large + duration: 100 + cpu: 10 + impacts: + - timestamp: 2023-07-06T00:00 + cloud-vendor: aws + cloud-instance-type: m5n.large + physical-processor: Intel Xeon Platinum 8259CL + duration: 100 + cpu: 10 +``` diff --git a/src/lib/cloud-instance-metadata/index.test.ts b/src/lib/cloud-instance-metadata/index.test.ts index 5fc0eba3f..da026a6e2 100644 --- a/src/lib/cloud-instance-metadata/index.test.ts +++ b/src/lib/cloud-instance-metadata/index.test.ts @@ -10,18 +10,18 @@ describe('ccf:configure test', () => { await expect( model.calculate([ { - 'cloud-instance-type': 't2.micro', + 'cloud-instance-type': 'm5n.large', 'cloud-vendor': 'aws', }, ]) ).resolves.toStrictEqual( expect.arrayContaining([ { - 'cloud-instance-type': 't2.micro', + 'cloud-instance-type': 'm5n.large', 'cloud-vendor': 'aws', - 'physical-processor': 'Intel Xeon E5-2676 v3', - 'vcpus-allocated': '1', - 'vcpus-total': '48', + 'physical-processor': 'Intel Xeon Platinum 8259CL', + 'vcpus-allocated': '2', + 'vcpus-total': '96', }, ]) );