From 0d13a7f22f78cb1279d5e121cac8c56759744be7 Mon Sep 17 00:00:00 2001 From: Scott Trent Date: Thu, 17 Oct 2024 16:20:56 +0900 Subject: [PATCH] two approaches Signed-off-by: Scott Trent --- samples/impact-framework/Dockerfile | 47 ------- samples/impact-framework/README.md | 33 +---- .../offClusterApproach/README.md | 29 ++++ .../{ => offClusterApproach}/htest.yaml | 6 +- .../{ => offClusterApproach}/ptest.yaml | 9 +- .../offClusterApproach/test/package-lock.json | 124 ++++++++++++++++++ .../offClusterApproach/test/package.json | 15 +++ .../onClusterApproach/Dockerfile | 38 ++++++ .../onClusterApproach/README.md | 39 ++++++ .../onClusterApproach/htest.yaml | 24 ++++ .../impact-framework.yaml | 0 .../onClusterApproach/ptest.yaml | 27 ++++ 12 files changed, 310 insertions(+), 81 deletions(-) delete mode 100644 samples/impact-framework/Dockerfile create mode 100644 samples/impact-framework/offClusterApproach/README.md rename samples/impact-framework/{ => offClusterApproach}/htest.yaml (77%) rename samples/impact-framework/{ => offClusterApproach}/ptest.yaml (74%) create mode 100644 samples/impact-framework/offClusterApproach/test/package-lock.json create mode 100644 samples/impact-framework/offClusterApproach/test/package.json create mode 100644 samples/impact-framework/onClusterApproach/Dockerfile create mode 100644 samples/impact-framework/onClusterApproach/README.md create mode 100644 samples/impact-framework/onClusterApproach/htest.yaml rename samples/impact-framework/{ => onClusterApproach}/impact-framework.yaml (100%) create mode 100644 samples/impact-framework/onClusterApproach/ptest.yaml diff --git a/samples/impact-framework/Dockerfile b/samples/impact-framework/Dockerfile deleted file mode 100644 index fa7acfb..0000000 --- a/samples/impact-framework/Dockerfile +++ /dev/null @@ -1,47 +0,0 @@ -FROM ubuntu:latest - -ENV NPM_CONFIG_PREFIX=/usr/local -ARG NPM_CONFIG_PREFIX=/usr/local - -WORKDIR /work -COPY ?test.yaml . - -RUN apt-get update -y && \ -apt-get upgrade -y && \ -apt-get install git curl vim lsb-release -y && \ -echo " --- Finished apt-get install" && \ -# npm install -g npm@latest && \ -# echo " --- Finished npm update" && \ -curl -fsSL https://deb.nodesource.com/setup_lts.x | bash && \ -apt-get upgrade -y && \ -apt-get install nodejs -y && \ -npm install -g npm@10.9.0 && \ -echo " --- Finished node update" && \ -npm install -g typescript && \ -echo " --- Finished typescript install" && \ -npm install -g rimraf && \ -echo " --- Finished rimraf install" && \ -npm install -g @types/node && \ -echo " --- Finished @types/node install" && \ -npm install -g --save-dev husky && \ -echo " --- Finished husky install" && \ -npm install -g "@grnsft/if" && \ -echo " --- Finished IF install" && \ -# npm install -g "@grnsft/if-core" && \ -# echo " --- Finished if-core install" && \ -git clone https://github.com/Green-Software-Foundation/if.git && cd if && npm install -g && npm install && npm link && cd - && \ -echo " --- Finished IF npm link" && \ -npm install -g "https://github.com/trent-s/prometheus-importer" && \ -echo " --- Finished PI install" && \ -git clone https://github.com/trent-s/prometheus-importer.git && cd prometheus-importer && \ -npm install --save-dev @types/node && npm run build && npm install -g && npm install && npm link && cd - && \ -echo " --- Finished cloning PI" && \ -npm install -g "https://github.com/trent-s/hello-plugin" && \ -git clone https://github.com/trent-s/hello-plugin.git && cd hello-plugin && \ -npm install --save-dev @types/node && npm run build && npm install -g && npm install && npm link && cd - && \ -cd if && npm link hello-plugin && cd - && \ -echo " --- Finished cloning and initializing hello-plugin" && \ -cd if && npm link prometheus-importer && cd - && \ -echo " --- Finished last link " && \ -chown -R 1000:1000 /work /usr/local/ - diff --git a/samples/impact-framework/README.md b/samples/impact-framework/README.md index 09382be..277018c 100644 --- a/samples/impact-framework/README.md +++ b/samples/impact-framework/README.md @@ -1,31 +1,10 @@ # Using SusQL with the Green Software Foundation's Impact Framework -### Using prebuilt container image: -- Ensure that you are logged into your cluster, then start the Impact Framework container: `oc apply -f impact-framework.yaml` -- Log into the newly created container: `oc rsh impact-framework bash` -- Try simple unit test: -``` -cd if -npm run if-run -- --manifest manifests/examples/builtins/sum/success.yml -``` -- Use SusQL data: (Edit HOST and BEARER_TOKEN as necessary.) -``` -cd if -echo "BEARER_TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) >>.env -echo "HOST=https://thanos-querier.openshift-monitoring.svc.cluster.local:9091" >>.env -npm run if-run -- --manifest ../ptest.yaml -``` +A large design point in using SusQL data with the Green Software Foundation's +Impact Framework is whether to run in a container ON the cluster, or run on a machine +external to the cluster. -### Building your own container image -For those who wish to build their own Impact Framework, log into both your -cluster and your container image repository, and run the following commands: -``` -export IMG=//=18", + "npm": ">=8" + } + }, + "node_modules/dotenv": { + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" + } + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "license": "MIT", + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch-commonjs": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch-commonjs/-/node-fetch-commonjs-3.3.2.tgz", + "integrity": "sha512-VBlAiynj3VMLrotgwOS3OyECFxas5y7ltLcK4t41lMUZeaK15Ym4QRkqN0EQKAFL42q9i21EPKjzLUPfltR72A==", + "license": "MIT", + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/prometheus-importer": { + "version": "0.2.2", + "resolved": "git+ssh://git@github.com/trent-s/prometheus-importer.git#00b87d68d4d5351ba3768d9a70c9e0f6e3f199bd", + "license": "MIT", + "dependencies": { + "@grnsft/if-core": "^0.0.7", + "dotenv": "16.3.1", + "node-fetch-commonjs": "^3.3.2", + "typescript": "^5.6.3", + "zod": "^3.23.8" + }, + "engines": { + "node": ">=18", + "npm": ">=8" + } + }, + "node_modules/typescript": { + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", + "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + } + } +} diff --git a/samples/impact-framework/offClusterApproach/test/package.json b/samples/impact-framework/offClusterApproach/test/package.json new file mode 100644 index 0000000..1ed8e6f --- /dev/null +++ b/samples/impact-framework/offClusterApproach/test/package.json @@ -0,0 +1,15 @@ +{ + "name": "test", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "prometheus-importer": "github:trent-s/prometheus-importer" + } +} diff --git a/samples/impact-framework/onClusterApproach/Dockerfile b/samples/impact-framework/onClusterApproach/Dockerfile new file mode 100644 index 0000000..08b9b11 --- /dev/null +++ b/samples/impact-framework/onClusterApproach/Dockerfile @@ -0,0 +1,38 @@ +FROM ubuntu:latest + +ENV NPM_CONFIG_PREFIX=/usr/local +ARG NPM_CONFIG_PREFIX=/usr/local + +WORKDIR /work +COPY ?test.yaml . + +RUN apt-get update -y && \ +apt-get upgrade -y && \ +apt-get install git curl vim lsb-release -y && \ +echo " --- Finished apt-get install" && \ +# npm install -g npm@latest && \ +# echo " --- Finished npm update" && \ +curl -fsSL https://deb.nodesource.com/setup_lts.x | bash && \ +apt-get upgrade -y && \ +apt-get install nodejs -y && \ +npm install -g npm@10.9.0 && \ +echo " --- Finished node update" && \ +npm install -g typescript rimraf husky @grnsft/if && \ +echo " --- Finished if install" && \ +# npm install -g @types/node && \ +# echo " --- Finished @types/node install" && \ +# git clone https://github.com/Green-Software-Foundation/if.git && cd if && npm install -g && npm install && npm link && cd - && \ +# echo " --- Finished IF npm link" && \ +# npm install -g "https://github.com/trent-s/prometheus-importer" && \ +# echo " --- Finished PI install" && \ +# git clone https://github.com/trent-s/prometheus-importer.git && cd prometheus-importer && \ +# npm install --save-dev @types/node && npm run build && npm install -g && npm install && npm link && cd - && \ +# echo " --- Finished cloning PI" && \ +# npm install -g "https://github.com/trent-s/hello-plugin" && \ +# git clone https://github.com/trent-s/hello-plugin.git && cd hello-plugin && \ +# npm install --save-dev @types/node && npm run build && npm install -g && npm install && npm link && cd - && \ +# cd if && npm link hello-plugin && cd - && \ +# echo " --- Finished cloning and initializing hello-plugin" && \ +# cd if && npm link prometheus-importer && cd - && \ +# echo " --- Finished last link " && \ +chown -R 1000:1000 /work /usr/local/ diff --git a/samples/impact-framework/onClusterApproach/README.md b/samples/impact-framework/onClusterApproach/README.md new file mode 100644 index 0000000..f72c9c2 --- /dev/null +++ b/samples/impact-framework/onClusterApproach/README.md @@ -0,0 +1,39 @@ +# Using SusQL with the Green Software Foundation's Impact Framework + +The following README explains an approach to utilize SusQL data in the +Green Software Foundation's Impact Framework using a slightly modified version +of the PrometheusImporter plugin. The fundamental focus of this particular +approach is to run entirely on Cluster, and is based on OpenShift. + +However, this is a work in progress related to an apparent limitation +in the use of certain required nodejs functionality within a container. + +### Using prebuilt container image: +- Ensure that you are logged into your cluster, then start the Impact Framework container: `oc apply -f impact-framework.yaml` +- Log into the newly created container: `oc rsh impact-framework bash` +- Try simple unit test: +``` +cd if +npm run if-run -- --manifest manifests/examples/builtins/sum/success.yml +``` +- Use SusQL data: (Edit HOST and BEARER_TOKEN as necessary.) +``` +cd if +echo "BEARER_TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) >>.env +echo "HOST=https://thanos-querier.openshift-monitoring.svc.cluster.local:9091" >>.env +npm run if-run -- --manifest ../ptest.yaml +``` + +### Building your own container image +For those who wish to build their own Impact Framework, log into both your +cluster and your container image repository, and run the following commands: +``` +export IMG=//