Skip to content

Commit 05e59a2

Browse files
committed
fixed grafana plots, added example scripts for each of provided langs, updated style of Editor component
1 parent ad583dd commit 05e59a2

File tree

8 files changed

+235
-34
lines changed

8 files changed

+235
-34
lines changed

backend/app/api/routes/execution.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
from app.core.logging import logger
33
from app.core.metrics import ACTIVE_EXECUTIONS, EXECUTION_DURATION, SCRIPT_EXECUTIONS
44
from app.schemas.execution import (
5+
ExampleScripts,
56
ExecutionRequest,
67
ExecutionResponse,
78
ExecutionResult,
8-
K8SResourceLimits,
9+
ResourceLimits,
910
ResourceUsage,
1011
)
1112
from app.services.execution_service import ExecutionService, get_execution_service
@@ -143,18 +144,28 @@ async def get_result(
143144
)
144145

145146

146-
@router.get("/k8s-limits", response_model=K8SResourceLimits)
147+
@router.get("/example-scripts", response_model=ExampleScripts)
148+
async def get_example_scripts(
149+
execution_service: ExecutionService = Depends(get_execution_service),
150+
) -> ExampleScripts:
151+
logger.info("Received example scripts request")
152+
scripts = await execution_service.get_example_scripts()
153+
logger.info("Example scripts retrieved successfully")
154+
return ExampleScripts(scripts=scripts)
155+
156+
157+
@router.get("/k8s-limits", response_model=ResourceLimits)
147158
async def get_k8s_resource_limits(
148159
execution_service: ExecutionService = Depends(get_execution_service),
149-
) -> K8SResourceLimits:
160+
) -> ResourceLimits:
150161
logger.info("Retrieving K8s resource limits", extra={"endpoint": "/k8s-limits"})
151162

152163
try:
153164
limits = await execution_service.get_k8s_resource_limits()
154165
logger.info(
155166
"K8s resource limits retrieved successfully", extra={"limits": limits}
156167
)
157-
return K8SResourceLimits(**limits)
168+
return ResourceLimits(**limits)
158169

159170
except Exception as e:
160171
logger.error(

backend/app/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Optional
22

3+
from app.runtime_registry import EXAMPLE_SCRIPTS as EXEC_EXAMPLE_SCRIPTS
34
from app.runtime_registry import SUPPORTED_RUNTIMES as RUNTIME_MATRIX
45
from pydantic import Field
56
from pydantic_settings import BaseSettings
@@ -31,6 +32,10 @@ class Settings(BaseSettings):
3132
default_factory=lambda: RUNTIME_MATRIX
3233
)
3334

35+
EXAMPLE_SCRIPTS: dict[str, str] = Field(
36+
default_factory=lambda: EXEC_EXAMPLE_SCRIPTS
37+
)
38+
3439
PROMETHEUS_URL: str = "http://prometheus:9090"
3540

3641
TESTING: bool = False

backend/app/runtime_registry.py

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55

66
class RuntimeConfig(NamedTuple):
7-
image: str # Full Docker image reference
8-
file_name: str # Name that will be mounted under /scripts/
7+
image: str # Full Docker image reference
8+
file_name: str # Name that will be mounted under /scripts/
99
command: List[str] # Entrypoint executed inside the container
1010

1111

@@ -38,10 +38,105 @@ class RuntimeConfig(NamedTuple):
3838
"versions": ["1.20", "1.21", "1.22"],
3939
"image_tpl": "golang:{version}-alpine",
4040
"file_ext": "go",
41-
"interpreter": ["sh", "-c", "go run /scripts/main.go"],
41+
"interpreter": ["go", "run"],
4242
},
4343
}
4444

45+
EXAMPLE_SCRIPTS: Dict[str, str] = {
46+
"python": """
47+
# This f-string formatting works on all supported Python versions (3.7+)
48+
py_version = "3.x"
49+
print(f"Hello from a Python {py_version} script!")
50+
51+
# The following block uses Structural Pattern Matching,
52+
# which was introduced in Python 3.10.
53+
# THIS WILL CAUSE A SYNTAX ERROR ON VERSIONS < 3.10.
54+
55+
lang_code = 1
56+
match lang_code:
57+
case 1:
58+
print("Structural Pattern Matching is available on this version (Python 3.10+).")
59+
case _:
60+
print("Default case.")
61+
""",
62+
"node": """
63+
// This works on all supported Node versions (18+)
64+
console.log(`Hello from Node.js ${process.version}!`);
65+
66+
// The Promise.withResolvers() static method was introduced in Node.js 22.
67+
// This will throw a TypeError on versions < 22.
68+
if (typeof Promise.withResolvers === 'function') {
69+
const { promise, resolve } = Promise.withResolvers();
70+
console.log("Promise.withResolvers() is supported (Node.js 22+).");
71+
resolve('Success');
72+
promise.then(msg => console.log(`Resolved with: ${msg}`));
73+
} else {
74+
console.log("Promise.withResolvers() is not supported on this version.");
75+
}
76+
""",
77+
"ruby": """
78+
# This works on all supported Ruby versions (3.1+)
79+
puts "Hello from Ruby #{RUBY_VERSION}!"
80+
81+
# The Data class for immutable value objects was introduced in Ruby 3.2.
82+
# This will cause an error on Ruby 3.1.
83+
begin
84+
# This line will fail on Ruby < 3.2
85+
Point = Data.define(:x, :y)
86+
p = Point.new(1, 2)
87+
puts "Data objects are supported (Ruby 3.2+). Created point: #{p.inspect}"
88+
rescue NameError
89+
puts "Data objects are not supported on this version."
90+
end
91+
""",
92+
"bash": """
93+
# This works on any modern Bash version
94+
echo "Hello from Bash version $BASH_VERSION"
95+
96+
# BASH_VERSINFO is an array holding version details.
97+
# We can check the major and minor version numbers.
98+
echo "Bash major version: ${BASH_VERSINFO[0]}"
99+
echo "Bash minor version: ${BASH_VERSINFO[1]}"
100+
101+
# The ${var@U} expansion for uppercasing was added in Bash 5.2
102+
if [[ "${BASH_VERSINFO[0]}" -ge 5 && "${BASH_VERSINFO[1]}" -ge 2 ]]; then
103+
my_var="hello"
104+
echo "Testing variable expansion (Bash 5.2+ feature)..."
105+
echo "Original: $my_var, Uppercased: ${my_var@U}"
106+
else
107+
echo "The '${var@U}' expansion is not available in this Bash version."
108+
fi
109+
""",
110+
"go": """
111+
package main
112+
113+
import (
114+
"fmt"
115+
"runtime"
116+
)
117+
118+
// This function uses generics, available since Go 1.18,
119+
// so it will work on all supported versions (1.20+).
120+
func Print[T any](s T) {
121+
fmt.Println(s)
122+
}
123+
124+
func main() {
125+
Print(fmt.Sprintf("Hello from Go version %s!", runtime.Version()))
126+
127+
// The built-in 'clear' function for maps and slices
128+
// was introduced in Go 1.21.
129+
// THIS WILL FAIL TO COMPILE on Go 1.20.
130+
myMap := make(map[string]int)
131+
myMap["a"] = 1
132+
Print(fmt.Sprintf("Map before clear: %v", myMap))
133+
clear(myMap) // This line will fail on Go < 1.21
134+
Print(fmt.Sprintf("Map after 'clear' (Go 1.21+ feature): length is %d", len(myMap)))
135+
}
136+
""",
137+
}
138+
139+
45140
def _make_runtime_configs() -> Dict[str, Dict[str, RuntimeConfig]]:
46141
registry: Dict[str, Dict[str, RuntimeConfig]] = {}
47142

backend/app/schemas/execution.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ class Config:
8686
from_attributes = True
8787

8888

89-
class K8SResourceLimits(BaseModel):
89+
class ResourceLimits(BaseModel):
9090
cpu_limit: str
9191
memory_limit: str
9292
cpu_request: str
9393
memory_request: str
9494
execution_timeout: int
9595
supported_runtimes: dict[str, list[str]]
96+
97+
98+
class ExampleScripts(BaseModel):
99+
scripts: Dict[str, str] # lang: str with script

backend/app/services/execution_service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ async def get_k8s_resource_limits(self) -> Dict[str, Any]:
5353
"supported_runtimes": self.settings.SUPPORTED_RUNTIMES,
5454
}
5555

56+
# for whatever reason mypy is dumb and can't defer type of EXAMPLE_SCRIPTS
57+
# -> ignoring type
58+
async def get_example_scripts(self) -> Dict[str, str]:
59+
return self.settings.EXAMPLE_SCRIPTS # type: ignore
60+
5661
async def _mark_running_when_scheduled(
5762
self,
5863
pod_name: str,

backend/grafana/provisioning/dashboards/integr8scode.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"uid": "PBFA97CFB590B2093"
6666
},
6767
"editorMode": "code",
68-
"expr": "rate(script_executions_total[5m])",
68+
"expr": "increase(script_executions_total[5m])",
6969
"instant": false,
7070
"legendFormat": "{{lang_and_version}} {{status}}",
7171
"range": true,

backend/prometheus/prometheus.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
global:
2-
scrape_interval: 15s
3-
evaluation_interval: 15s
2+
scrape_interval: 3s
3+
evaluation_interval: 3s
44

55
rule_files:
66
- "alert_rules.yml"
@@ -20,10 +20,10 @@ scrape_configs:
2020
- targets: ['backend:443']
2121
metric_relabel_configs:
2222
- source_labels: [ lang_and_version ]
23-
regex: '(.+)-(.+)'
23+
regex: '^(|.+-.+)$'
2424
action: keep
2525
- source_labels: [ status ]
26-
regex: '(success|error|timeout|invalid_input|unknown)'
26+
regex: '^(success|error|timeout|invalid_input|unknown)?$'
2727
action: keep
2828

2929
- job_name: 'prometheus'

0 commit comments

Comments
 (0)