Skip to content

Commit

Permalink
two approaches
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Trent <[email protected]>
  • Loading branch information
trent-s committed Oct 28, 2024
1 parent 2492e5d commit 0d13a7f
Show file tree
Hide file tree
Showing 12 changed files with 310 additions and 81 deletions.
47 changes: 0 additions & 47 deletions samples/impact-framework/Dockerfile

This file was deleted.

33 changes: 6 additions & 27 deletions samples/impact-framework/README.md
Original file line number Diff line number Diff line change
@@ -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=<YOURIMAGEREPO>/<YOURID>/<YOURIMAGENAME
podman build --tag ${IMG} .
podman push ${IMG}
```
Then edit `impact-framework.yaml` so that `image` points to your newly built image.
This directory contains two directories with experiments into both approaches:

Notes:
- `oc` and `kubectl` are (should be) interchangable in this context.
- `podman` and `docker` are (should be) interchangable in this context.
- [onClusterApproach](onClusterApproach)
- [offClusterApproach](offClusterApproach)
29 changes: 29 additions & 0 deletions samples/impact-framework/offClusterApproach/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Using SusQL with the Green Software Foundation's Impact Framework

This particular experiment was performed using a recent RHEL 9 x86 machine,
however, any OS that supports a sufficiently recent version of nodejs should
work in principle.

### steps
- Ensure that you are logged into your cluster and can use the `oc` (or `kubectl` command).
- Make sure that a recent version of `node` is installed. (This test used v22.9.0)
- Install Impact Framework
- `npm install -g @grnsft/if`
- Install Prometheus Importer
- `npm install -g "https://github.com/trent-s/prometheus-importer"`
- Update, just to be sure:
- `cd test; npm update; cd -`

- Create required credential file, and attempt to use prometheus-importer:
```
cd test
echo "BEARER_TOKEN="$(oc whoami -t) >.env
echo HOST=https://$(oc get routes -n openshift-monitoring thanos-querier -o jsonpath='{.status.ingress[0].host}') >>.env
if-run --manifest ../ptest.yaml --debug
cd -
```


Note:
- `oc` and `kubectl` are (should be) interchangable in this context.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ description: simple verification of plugin tech
tags: null
initialize:
plugins:
hello-plugin:
'hello-plugin':
method: HelloPlugin
path: "https://github.com/trent-s/hello-plugin"
path: 'https://github.com/trent-s/hello-plugin'
config:
allow-padding: true
outputs:
- yaml
tree:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ initialize:
plugins:
prometheus-importer:
method: PrometheusImporter
path: 'prometheus-importer'
global-config:
path: 'https://github.com/trent-s/prometheus-importer'
config:
step: '1h'
start: '2024-09-14T23:50:30.781Z'
end: '2024-10-14T00:00:30.781Z'
start: '2024-09-16T23:50:30.000Z'
end: '2024-10-16T00:00:30.000Z'
query: 'rate(susql_container_joules_total)[1m])'
metricLabels:
- name
metricName: 'energy'
defaultLabels:
duration: 3600
cloud/vendor: 'ibm'
cloud/instance-type: 'medium'
outputs:
- yaml
tree:
Expand Down
124 changes: 124 additions & 0 deletions samples/impact-framework/offClusterApproach/test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions samples/impact-framework/offClusterApproach/test/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
38 changes: 38 additions & 0 deletions samples/impact-framework/onClusterApproach/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 [email protected] && \
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/
39 changes: 39 additions & 0 deletions samples/impact-framework/onClusterApproach/README.md
Original file line number Diff line number Diff line change
@@ -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=<YOURIMAGEREPO>/<YOURID>/<YOURIMAGENAME
podman build --tag ${IMG} .
podman push ${IMG}
```
Then edit `impact-framework.yaml` so that `image` points to your newly built image.

Notes:
- `oc` and `kubectl` are (should be) interchangable in this context.
- `podman` and `docker` are (should be) interchangable in this context.
24 changes: 24 additions & 0 deletions samples/impact-framework/onClusterApproach/htest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: hello plugin test
description: simple verification of plugin tech
tags: null
initialize:
plugins:
'hello-plugin':
method: HelloPlugin
path: 'https://github.com/trent-s/hello-plugin'
config:
allow-padding: true
outputs:
- yaml
tree:
children:
child:
pipeline:
- hello-plugin
inputs:
- timestamp: 2023-08-06T00:00
duration: 3600
carbon: 30
- timestamp: 2023-09-06T00:00
duration: 3600
carbon: 30
Loading

0 comments on commit 0d13a7f

Please sign in to comment.