Skip to content
This repository has been archived by the owner on Jun 25, 2023. It is now read-only.

solution #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
12 changes: 12 additions & 0 deletions autotests/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM grafana/xk6 as xk6_builder
RUN xk6 build --output k6 --with github.com/szkiba/xk6-faker@latest \
--with github.com/grafana/xk6-output-prometheus-remote@latest


FROM grafana/k6

WORKDIR /app/
COPY src/main.js /app/
COPY --from=xk6_builder /xk6/k6 /usr/bin/k6

ENTRYPOINT k6 run -o xk6-prometheus-rw main.js
193 changes: 97 additions & 96 deletions autotests/app/src/main.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,111 @@
import http from 'k6/http';
import { check } from 'k6';
import { Faker } from "k6/x/faker"

let f = new Faker();

export const options = {
// Tag for grafana dashboard
tags: {
testid: `${__ENV.PARTICIPANT_NAME}`,
},
scenarios: {
does_it_even_work: {
executor: 'constant-arrival-rate',
rate: 1,
timeUnit: '1s',
duration: '1m',
preAllocatedVUs: 1,
maxVUs: 1,
exec: 'post_radom',
},

highload_scenario: {
executor: 'ramping-arrival-rate',
startTime: '61s',
preAllocatedVUs: 10,
maxVUs: 50,
timeUnit: '1s',
startRate: 1,
stages: [
{ target: 10, duration: '5s' },
{ target: 30, duration: '5s' },
{ target: 60, duration: '10s' },
{ target: 60, duration: '1m' },
{ target: 40, duration: '1m' },
{ target: 60, duration: '10s' },
{ target: 10, duration: '30s' },
{ target: 0, duration: '5s' },
],
exec: 'post_radom',
},
import http from 'k6/http';
import { check } from 'k6';
import { Faker } from "k6/x/faker"

spike_scenario: {
executor: 'ramping-arrival-rate',
startTime: '247s',
preAllocatedVUs: 10,
maxVUs: 50,
timeUnit: '1s',
startRate: 1,
stages: [
{ target: 10, duration: '5s' },
{ target: 30, duration: '5s' },
{ target: 200, duration: '10s' },
{ target: 200, duration: '2m' },
{ target: 0, duration: '5s' },
],
exec: 'post_radom',
},
let f = new Faker();

stress_speed_test: {
executor: 'shared-iterations',
startTime: '392s',
vus: 10,
iterations: 1000000,
maxDuration: '2m',
exec: 'post_radom',
export const options = {
// Tag for grafana dashboard
tags: {
testid: `${__ENV.PARTICIPANT_NAME}`,
},

scenarios: {
does_it_even_work: {
executor: 'constant-arrival-rate',
rate: 1,
timeUnit: '1s',
duration: '1m',
preAllocatedVUs: 1,
maxVUs: 1,
exec: 'post_radom',
},

highload_scenario: {
executor: 'ramping-arrival-rate',
startTime: '61s',
preAllocatedVUs: 10,
maxVUs: 50,
timeUnit: '1s',
startRate: 1,
stages: [
{ target: 10, duration: '5s' },
{ target: 30, duration: '5s' },
{ target: 60, duration: '10s' },
{ target: 60, duration: '1m' },
{ target: 40, duration: '1m' },
{ target: 60, duration: '10s' },
{ target: 10, duration: '30s' },
{ target: 0, duration: '5s' },
],
exec: 'post_radom',
},

spike_scenario: {
executor: 'ramping-arrival-rate',
startTime: '247s',
preAllocatedVUs: 10,
maxVUs: 50,
timeUnit: '1s',
startRate: 1,
stages: [
{ target: 10, duration: '5s' },
{ target: 30, duration: '5s' },
{ target: 200, duration: '10s' },
{ target: 200, duration: '2m' },
{ target: 0, duration: '5s' },
],
exec: 'post_radom',
},

stress_speed_test: {
executor: 'shared-iterations',
startTime: '392s',
vus: 10,
iterations: 1000000,
maxDuration: '2m',
exec: 'post_radom',
},

}
}
}


export function post_radom() {
let text = ""
// 0.5 percent of requests will be empty
if (Math.random() < 0.005) {
text = ""
} else {
text = f.hipsterSentence(f.randomInt([0, 10])) + f.emoji() + f.url() + f.hipsterSentence(f.randomInt([0, 10])) + ". " + f.regex("[\x00-\x7F]{5,20}") + " " + f.bitcoinAddress() + f.emoji() + " " + f.hackerPhrase(f.randomInt([0, 10]))
}
export function post_radom() {
let text = ""
// 0.5 percent of requests will be empty
if (Math.random() < 0.005) {
text = ""
} else {
text = f.hipsterSentence(f.randomInt([0, 10])) + f.emoji() + f.url() + f.hipsterSentence(f.randomInt([0, 10])) + ". " + f.regex("[\x00-\x7F]{5,20}") + " " + f.bitcoinAddress() + f.emoji() + " " + f.hackerPhrase(f.randomInt([0, 10]))
}

console.log("mytext: " + text)
console.log("mytext: " + text)

// post json to the api
const res = http.post(`${__ENV.api_host}`, JSON.stringify(text), {
headers: {
'Content-Type': 'application/json',
},
});
const languages_list = ["Arabic", "Basque", "Breton", "Catalan", "Chinese_China", "Chinese_Hongkong", "Chinese_Taiwan", "Chuvash", "Czech", "Dhivehi", "Dutch", "English", "Esperanto", "Estonian", "French", "Frisian", "Georgian", "German", "Greek", "Hakha_Chin", "Indonesian", "Interlingua", "Italian", "Japanese", "Kabyle", "Kinyarwanda", "Kyrgyz", "Latvian", "Maltese", "Mongolian", "Persian", "Polish", "Portuguese", "Romanian", "Romansh_Sursilvan", "Russian", "Sakha", "Slovenian", "Spanish", "Swedish", "Tamil", "Tatar", "Turkish", "Ukranian", "Welsh"]
// post json to the API
const res = http.post('http://localhost:8000/process', { text: text }, {
headers: {
'Content-Type': 'application/json',
'accept': 'application/json',
},
});
const languages_list = ["Arabic", "Basque", "Breton", "Catalan", "Chinese_China", "Chinese_Hongkong", "Chinese_Taiwan", "Chuvash", "Czech", "Dhivehi", "Dutch", "English", "Esperanto", "Estonian", "French", "Frisian", "Georgian", "German", "Greek", "Hakha_Chin", "Indonesian", "Interlingua", "Italian", "Japanese", "Kabyle", "Kinyarwanda", "Kyrgyz", "Latvian", "Maltese", "Mongolian", "Persian", "Polish", "Portuguese", "Romanian", "Romansh_Sursilvan", "Russian", "Sakha", "Slovenian", "Spanish", "Swedish", "Tamil", "Tatar", "Turkish", "Ukranian", "Welsh"]


check(res, {
'is status 200': (r) => r.status === 200,
"model 1 score valid": res => res.json().cardiffnlp.score > 0,
"model 1 label valid": res => res.json().cardiffnlp.label === "POSITIVE" || res.json().cardiffnlp.label === "NEGATIVE" || res.json().cardiffnlp.label === "NEUTRAL",
check(res, {
'is status 200': (r) => r.status === 200,
"model 1 score valid": res => res.json().cardiffnlp.score > 0,
"model 1 label valid": res => res.json().cardiffnlp.label === "POSITIVE" || res.json().cardiffnlp.label === "NEGATIVE" || res.json().cardiffnlp.label === "NEUTRAL",

"model 2 score valid": res => res.json().ivanlau.score > 0,
"model 2 label valid": res => languages_list.includes(res.json().ivanlau.label),
"model 2 score valid": res => res.json().ivanlau.score > 0,
"model 2 label valid": res => languages_list.includes(res.json().ivanlau.label),

"model 3 score valid": res => res.json().svalabs.score > 0,
"model 3 label valid": res => res.json().svalabs.label === "SPAM" || res.json().svalabs.label === "HAM",
"model 3 score valid": res => res.json().svalabs.score > 0,
"model 3 label valid": res => res.json().svalabs.label === "SPAM" || res.json().svalabs.label === "HAM",

"model 4 score valid": res => res.json().EIStakovskii.score > 0,
"model 4 label valid": res => res.json().EIStakovskii.label === "LABEL_0" || res.json().EIStakovskii.label === "LABEL_1",
"model 4 score valid": res => res.json().EIStakovskii.score > 0,
"model 4 label valid": res => res.json().EIStakovskii.label === "LABEL_0" || res.json().EIStakovskii.label === "LABEL_1",

"model 5 score valid": res => res.json().jy46604790.score > 0,
"model 5 label valid": res => res.json().jy46604790.label === "LABEL_0" || res.json().jy46604790.label === "LABEL_1",
});
}
"model 5 score valid": res => res.json().jy46604790.score > 0,
"model 5 label valid": res => res.json().jy46604790.label === "LABEL_0" || res.json().jy46604790.label === "LABEL_1",
});
}
4 changes: 2 additions & 2 deletions autotests/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ global:
activeDeadlineSeconds: 3600 # 1h

env:
PARTICIPANT_NAME: <REPLACE_WITH_USERNAME>
api_host: http://inca-smc-mlops-challenge-solution.default.svc.cluster.local/<REPLACE_WITH_ENDPOINT>
PARTICIPANT_NAME: Khush Patel
api_host: http://inca-smc-mlops-challenge-solution.default.svc.cluster.local/8000
khushpatel2002 marked this conversation as resolved.
Show resolved Hide resolved

# K6, do not edit!
K6_PROMETHEUS_RW_SERVER_URL: http://kube-prometheus-stack-prometheus.monitoring.svc.cluster.local:9090/api/v1/write
Expand Down
23 changes: 23 additions & 0 deletions solution/helm/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
__pycache__
*.pyc
*.pyo
*.pyd
.Python
env/
venv/
pip-log.txt
pip-delete-this-directory.txt
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.log
.git
.gitignore
.mypy_cache
.pytest_cache
.hypothesis
.idea
11 changes: 11 additions & 0 deletions solution/helm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.10.11-slim-bullseye
khushpatel2002 marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /code

COPY ./requirements.txt /code/requirements.txt

COPY ./app.py /code/app.py

RUN pip install -r requirements.txt

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
Loading