Green-Software-Foundation / if

Impact Framework
https://if.greensoftware.foundation/
MIT License
136 stars 37 forks source link

Move time-sync to builtin feature #822

Open zanete opened 2 weeks ago

zanete commented 2 weeks ago

Why: Sub of #763 What: Refactor TimeSync so that it is an IF builtin feature and not a plugin. It accepts config from the top level manifest context and is automatically executed after regroup if the config exists.

Blocked by:

Scope of work:

Acceptance criteria

name: time-sync
description: successful path
tags:
time-sync:
    start-time: '2023-12-12T00:00:00.000Z'
    end-time: '2023-12-12T00:01:00.000Z'
    interval: 5
    allow-padding: true
initialize:
  plugins:
    sum:
      method: Sum
      path: "builtin"
      global-config:
        input-parameters: ["energy-cpu", "energy-mem"]
        output-parameter: "energy"
tree:
  children:
    child:
      pipeline:
        observe:
        regroup:
        compute:
          - sum
      config:
      inputs:
        - timestamp: '2023-12-12T00:00:00.000Z'
          duration: 1
          energy-cpu: 0.001
          energy-mem: 0.001
        - timestamp: '2023-12-12T00:00:01.000Z'
          duration: 5
          energy-cpu: 0.001
          energy-mem: 0.001
        - timestamp: '2023-12-12T00:00:06.000Z'
          duration: 7
          energy-cpu: 0.001
          energy-mem: 0.001
        - timestamp: '2023-12-12T00:00:13.000Z'
          duration: 30
          energy-cpu: 0.001
          energy-mem: 0.001

THEN it runs successfully and the output is:

name: time-sync
description: successful path
tags: null
time-sync:
    start-time: '2023-12-12T00:00:00.000Z'
    end-time: '2023-12-12T00:01:00.000Z'
    interval: 5
    allow-padding: true
initialize:
    sum:
      path: builtin
      method: Sum
      global-config:
        input-parameters:
          - energy-cpu
          - energy-mem
        output-parameter: energy
execution:
  command: >-
    /home/user/.npm/_npx/1bf7c3c15bf47d04/node_modules/.bin/ts-node
    /home/uesr/Code/if/src/index.ts -m manifests/plugins/time-sync/success.yml -s
  environment:
    if-version: 0.4.0
    os: linux
    os-version: 5.15.0-107-generic
    node-version: 21.4.0
    date-time: 2024-06-17T08:23:25.105Z (UTC)
    dependencies:
      - '@babel/core@7.22.10'
      - '@babel/preset-typescript@7.23.3'
      - '@commitlint/cli@18.6.0'
      - '@commitlint/config-conventional@18.6.0'
      - '@grnsft/if-core@0.0.3'
      - '@jest/globals@29.7.0'
      - '@types/jest@29.5.8'
      - '@types/js-yaml@4.0.9'
      - '@types/luxon@3.4.2'
      - '@types/node@20.9.0'
      - axios-mock-adapter@1.22.0
      - axios@1.7.2
      - csv-parse@5.5.6
      - csv-stringify@6.4.6
      - fixpack@4.0.0
      - gts@5.2.0
      - husky@8.0.3
      - jest@29.7.0
      - js-yaml@4.1.0
      - lint-staged@15.2.2
      - luxon@3.4.4
      - release-it@16.3.0
      - rimraf@5.0.5
      - ts-command-line-args@2.5.1
      - ts-jest@29.1.1
      - typescript-cubic-spline@1.0.1
      - typescript@5.2.2
      - winston@3.11.0
      - zod@3.22.4
  status: success
tree:
  children:
    child:
      pipeline:
        observe:
        regroup:
        compute:
          - sum
      config: null
      inputs:
        - timestamp: '2023-12-12T00:00:00.000Z'
          duration: 1
          energy-cpu: 0.001
          energy-mem: 0.001
        - timestamp: '2023-12-12T00:00:01.000Z'
          duration: 5
          energy-cpu: 0.001
          energy-mem: 0.001
        - timestamp: '2023-12-12T00:00:06.000Z'
          duration: 7
          energy-cpu: 0.001
          energy-mem: 0.001
        - timestamp: '2023-12-12T00:00:13.000Z'
          duration: 30
          energy-cpu: 0.001
          energy-mem: 0.001
      outputs:
        - timestamp: '2023-12-12T00:00:00.000Z'
          duration: 5
          energy-cpu: 0.0018000000000000004
          energy-mem: 0.0018000000000000004
          energy: 0.0036000000000000008
        - timestamp: '2023-12-12T00:00:05.000Z'
          duration: 5
          energy-cpu: 0.0007714285714285716
          energy-mem: 0.0007714285714285716
          energy: 0.0015428571428571431
        - timestamp: '2023-12-12T00:00:10.000Z'
          duration: 5
          energy-cpu: 0.0004952380952380952
          energy-mem: 0.0004952380952380952
          energy: 0.0009904761904761905
        - timestamp: '2023-12-12T00:00:15.000Z'
          duration: 5
          energy-cpu: 0.0001666666666666667
          energy-mem: 0.0001666666666666667
          energy: 0.0003333333333333334
        - timestamp: '2023-12-12T00:00:20.000Z'
          duration: 5
          energy-cpu: 0.0001666666666666667
          energy-mem: 0.0001666666666666667
          energy: 0.0003333333333333334
        - timestamp: '2023-12-12T00:00:25.000Z'
          duration: 5
          energy-cpu: 0.0001666666666666667
          energy-mem: 0.0001666666666666667
          energy: 0.0003333333333333334
        - timestamp: '2023-12-12T00:00:30.000Z'
          duration: 5
          energy-cpu: 0.0001666666666666667
          energy-mem: 0.0001666666666666667
          energy: 0.0003333333333333334
        - timestamp: '2023-12-12T00:00:35.000Z'
          duration: 5
          energy-cpu: 0.0001666666666666667
          energy-mem: 0.0001666666666666667
          energy: 0.0003333333333333334
        - timestamp: '2023-12-12T00:00:40.000Z'
          duration: 5
          energy-cpu: 0.0001
          energy-mem: 0.0001
          energy: 0.0002
        - timestamp: '2023-12-12T00:00:45.000Z'
          duration: 5
          energy-cpu: 0
          energy-mem: 0
          energy: 0
        - timestamp: '2023-12-12T00:00:50.000Z'
          duration: 5
          energy-cpu: 0
          energy-mem: 0
          energy: 0
        - timestamp: '2023-12-12T00:00:55.000Z'
          duration: 5
          energy-cpu: 0
          energy-mem: 0
          energy: 0
        - timestamp: '2023-12-12T00:01:00.000Z'
          duration: 1
          energy-cpu: 0
          energy-mem: 0
          energy: 0

e.g. this manifest should trigger the intended behaviour

name: time-sync
description: successful path
tags:
time-sync:
      start-time: '2023-12-12T00:00:00.000Z'
      end-time: '2023-12-12T00:01:00.000Z'
      interval: 5
      allow-padding: true
initialize:
  plugins:
    sum:
      method: Sum
      path: "builtin"
      global-config:
        input-parameters: ["energy-cpu", "energy-mem"]
        output-parameter: "energy"
tree:
  children:
    child:
      pipeline:
        observe:
        regroup:
          - cloud/instance-type
        compute:
          - sum
      config:
      inputs:
        - timestamp: '2023-12-12T00:00:00.000Z'
          duration: 1
          energy-cpu: 0.001
          energy-mem: 0.001
          cloud/instance-type: A1
        - timestamp: '2023-12-12T00:00:01.000Z'
          duration: 5
          energy-cpu: 0.001
          energy-mem: 0.001
          cloud/instance-type: A1
        - timestamp: '2023-12-12T00:00:06.000Z'
          duration: 7
          energy-cpu: 0.001
          energy-mem: 0.001
          cloud/instance-type: A1
        - timestamp: '2023-12-12T00:00:13.000Z'
          duration: 30
          energy-cpu: 0.001
          energy-mem: 0.001
          cloud/instance-type: A1
        - timestamp: '2023-12-12T00:00:00.000Z'
          duration: 1
          energy-cpu: 0.001
          energy-mem: 0.001
          cloud/instance-type: B1
        - timestamp: '2023-12-12T00:00:01.000Z'
          duration: 5
          energy-cpu: 0.001
          energy-mem: 0.001
          cloud/instance-type: B1
        - timestamp: '2023-12-12T00:00:06.000Z'
          duration: 7
          energy-cpu: 0.001
          energy-mem: 0.001
          cloud/instance-type: B1
        - timestamp: '2023-12-12T00:00:13.000Z'
          duration: 30
          energy-cpu: 0.001
          energy-mem: 0.001
          cloud/instance-type: B1
zanete commented 1 week ago

@manushak @narekhovhannisyan please review ac to confirm you're ok with it