Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate rhoai #10

Merged
merged 24 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d1d578a
Merge branch 'validatedpatterns/main'
mamurak Aug 14, 2024
5e8b308
updated model training pipeline
mamurak Aug 14, 2024
8ec5f41
updated pipeline runtime image
mamurak Sep 4, 2024
9b091ed
added git push to push model notebook
mamurak Sep 25, 2024
e45ed73
Merge pull request #4 from mamurak/mamurak/industrial-edge-v2
mhjacks Sep 26, 2024
6e2115c
replaced seldon with modelmesh
mamurak Oct 8, 2024
4686d0a
Fix compatibility with seldon ml server
darkdoc Oct 16, 2024
814ae1d
Update iot-consumer for new anomaly prediction model (v2 pred.)
darkdoc Oct 15, 2024
eaeb6df
Merge pull request #1 from darkdoc/industrial-edge-v2
mamurak Oct 23, 2024
5eef9b5
added dev commit in push-model
mamurak Oct 23, 2024
6a4db66
added container sources
mamurak Oct 30, 2024
15301e8
changed push model notebook
mamurak Oct 30, 2024
9211e27
Merge pull request #5 from mamurak/mamurak/industrial-edge-v2
mbaldessari Oct 30, 2024
e2af3b0
Add a Makefile to use for containers
mbaldessari Nov 7, 2024
e9cdfb8
Add workflow to build the container and to run a simple jupiter invoc…
mbaldessari Nov 7, 2024
89a2bd4
Add dependabot for GH and Docker
mbaldessari Nov 7, 2024
61ef70d
Add gh action to push containers
mbaldessari Nov 7, 2024
d98b927
Merge pull request #6 from mbaldessari/add-container-gh-action
mbaldessari Nov 7, 2024
04bfdf4
Fix the aws bucket name and the model server name
mbaldessari Nov 15, 2024
981f489
Merge pull request #7 from mbaldessari/integrate_rhoai
mbaldessari Nov 15, 2024
8f40784
Don't print the git credentials on the notebook
mbaldessari Nov 16, 2024
d63b570
Merge pull request #8 from mbaldessari/dontprint-gitpass
mbaldessari Nov 16, 2024
5216ce1
Fix the URL + name of the inference-server
mbaldessari Nov 18, 2024
0a2ff43
Merge pull request #9 from mbaldessari/lastfix
mbaldessari Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
version: 2
updates:
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"

# Check for updates to GitHub Actions every week
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
18 changes: 18 additions & 0 deletions .github/workflows/container-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: "Container build and test"
on: [push, pull_request, workflow_call]
permissions: read-all

jobs:
podman-build:
name: Utility Container Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Utility Container Build
run: make build

- name: Run Container tests
run: make test
81 changes: 81 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
name: Docker build and push to quay

permissions: read-all

on:
push:
branches: ['main', 'integrate_rhoai']
# Publish semver tags as releases.
tags: ['v*.*.*']
pull_request:
branches: ['main', 'integrate_rhoai']

env:
REGISTRY: quay.io

jobs:
test:
uses: ./.github/workflows/container-test.yml

build-container-and-push:
needs: [test]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

strategy:
matrix:
include:
- dockerfile: ./container-source/Containerfile-runtime
image: quay.io/hybridcloudpatterns/manuela-runtime
- dockerfile: ./container-source/Containerfile-workbench
image: quay.io/hybridcloudpatterns/manuela-workbench

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: ${{ matrix.image }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
with:
context: container-source
file: ${{ matrix.dockerfile }}
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
TAG ?= latest
RUNTIME_CONTAINER ?= manuela-runtime:$(TAG)
WORKBENCH_CONTAINER ?= manuela-workbench:$(TAG)

##@ Help-related tasks
.PHONY: help
help: ## Help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^(\s|[a-zA-Z_0-9-])+:.*?##/ { printf " \033[36m%-35s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build-related tasks
.PHONY: build
build: build-runtime build-workbench test ## Build the runtime and the workbench container locally

.PHONY: build-runtime
build-runtime: ## build manuela-runtime container
cd ./container-source; buildah bud -f ./Containerfile-runtime --format docker -t $(RUNTIME_CONTAINER)

.PHONY: build-workbench
build-workbench: ## build manuela-workbench container
cd ./container-source; buildah bud -f ./Containerfile-workbench --format docker -t $(WORKBENCH_CONTAINER)

.PHONY: test
test: ## test the built containers
podman run -it --rm --net=host --entrypoint /bin/sh $(RUNTIME_CONTAINER) -c "jupyter --version"
podman run -it --rm --net=host --entrypoint /bin/sh $(WORKBENCH_CONTAINER) -c "jupyter --version"

.PHONY: clean
clean: ## Removes any previously built artifact
podman rmi $(RUNTIME_CONTAINER) $(WORKBENCH_CONTAINER)

.PHONY: super-linter
super-linter: ## Runs super linter locally
rm -rf .mypy_cache
podman run -e RUN_LOCAL=true -e USE_FIND_ALGORITHM=true \
-e VALIDATE_JAVASCRIPT_STANDARD=false \
-e VALIDATE_MARKDOWN=false \
-e VALIDATE_JAVASCRIPT_PRETTIER=false \
-e VALIDATE_JSCPD=false \
-e VALIDATE_JSON=false \
-e VALIDATE_JSON_PRETTIER=false \
-e VALIDATE_MARKDOWN_PRETTIER=false \
-e VALIDATE_BASH=false \
-e VALIDATE_BASH_EXEC=false \
-e VALIDATE_CHECKOV=false \
-e VALIDATE_CSS=false \
-e VALIDATE_CSS_PRETTIER=false \
-e VALIDATE_GITLEAKS=false \
-e VALIDATE_GOOGLE_JAVA_FORMAT=false \
-e VALIDATE_HTML=false \
-e VALIDATE_HTML_PRETTIER=false \
-e VALIDATE_JAVA=false \
-e VALIDATE_KUBERNETES_KUBECONFORM=false \
-e VALIDATE_NATURAL_LANGUAGE=false \
-e VALIDATE_SHELL_SHFMT=false \
-e VALIDATE_TYPESCRIPT_PRETTIER=false \
-e VALIDATE_TYPESCRIPT_STANDARD=false \
-e VALIDATE_YAML=false \
-e VALIDATE_YAML_PRETTIER=false \
-v $(PWD):/tmp/lint:rw,z \
-w /tmp/lint \
ghcr.io/super-linter/super-linter:slim-v7
31 changes: 21 additions & 10 deletions components/iot-consumer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const temperature_threshold = process.env.TEMPERATURE_THRESHOLD || 70.0;
const temperature_alert_enabled = ((process.env.TEMPERATURE_ALERT_ENABLED || "false") === 'true');
const vibration_alert_enabled = ((process.env.VIBRATION_ALERT_ENABLED || "false") === 'true');
const vibration_anomaly_enabled = ((process.env.VIBRATION_ANOMALY_ENABLED || "false") === 'true');

const anomaly_detection_model = process.env.ANOMALY_DETECTION_MODEL || 'anomaly-detection'
const anomaly_detection_url = process.env.ANOMALY_DETECTION_URL || 'http://anomaly-detection-anomaly-detection';
const anomaly_detection_url_path = process.env.ANOMALY_DETECTION_URL_PATH || `/v2/models/${anomaly_detection_model}/infer`;

// setup application
var mqtt = require('mqtt')
Expand Down Expand Up @@ -108,7 +111,7 @@ function get_list_last_values(id, value) {
if ( last_value_array_map[id] !== undefined) {
array = last_value_array_map[id]
}
array.unshift(value);
array.unshift(value);

if (array.length > episode_length) {
array.pop()
Expand All @@ -119,7 +122,7 @@ function get_list_last_values(id, value) {



var last_value_map = {};
var last_value_map = {};
async function check_anomaly(id, value) {
var result = false

Expand All @@ -128,25 +131,33 @@ async function check_anomaly(id, value) {
console.log('Anomaly detection for: %s, Val: %d', id, value );

l = get_list_last_values(id, value)

if (l.length == episode_length) {

var edgeAnomaly = { "data": { "ndarray": [l] }};

var edgeAnomaly = {
"inputs": [
{
"data": l,
"datatype": "FP32",
"shape": [1, 5]
}
]
}

try {
console.log('*AD* ID: %s, Val: %d', id, value );
const edgeAnomalyResponse = await request({
method: 'POST',
uri: anomaly_detection_url + '/api/v1.0/predictions',
uri: anomaly_detection_url + anomaly_detection_url_path,
body: edgeAnomaly,
json: true,
timeout: 1000
});

// log.debug("Edge Anomaly Repsonse: " + JSON.stringify(edgeAnomalyResponse)); //DELETE
// log.debug("Edge Anomaly Repsonse.data: " + JSON.stringify(edgeAnomalyResponse.data)); //DELETE
if ( parseInt(edgeAnomalyResponse["data"]["ndarray"][0]) == 1 ){

if ( parseInt(edgeAnomalyResponse["outputs"][0]["data"][0]) == 1 ){
result = true;
} else {
result = false;
Expand Down Expand Up @@ -195,7 +206,7 @@ function handleTemperature(message) {
var newData = data.replace(elements[2], modifiedValue);
message = Buffer.from(newData, 'utf8');
*/

io.sockets.emit("temperature-event", message);

// check for temperature threshold
Expand Down
8 changes: 8 additions & 0 deletions container-source/Containerfile-runtime
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM quay.io/modh/runtime-images:runtime-datascience-ubi9-python-3.11-2024b-20241004-69688c1

RUN pip install --upgrade pip==24.3.1 setuptools==75.3.0

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt && \
chmod -R g+w /opt/app-root/lib/python3.11/site-packages && \
fix-permissions /opt/app-root -P
8 changes: 8 additions & 0 deletions container-source/Containerfile-workbench
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM quay.io/modh/odh-generic-data-science-notebook:v3-2024b-20241004-69688c1

RUN pip install --upgrade pip==24.3.1 setuptools==75.3.0

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt && \
chmod -R g+w /opt/app-root/lib/python3.11/site-packages && \
fix-permissions /opt/app-root -P
7 changes: 7 additions & 0 deletions container-source/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gitpython==3.1.14
scikit-learn==1.3.0
joblib==1.3.1
pandas==2.2.2
numpy==1.26.4
boto3==1.34.135
pyyaml==6.0.1
Loading