Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
testing_system
cp.sh
swag
custom
17 changes: 15 additions & 2 deletions common/connectors/masterconn/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import (
"testing_system/common/connectors/invokerconn"
"testing_system/common/constants/verdict"
"testing_system/lib/customfields"
"time"
)

type InvokerJobResult struct {
JobID string `json:"JobID"`
Job *invokerconn.Job `json:"Job"`

Verdict verdict.Verdict `json:"Verdict"`
Points *float64 `json:"Points,omitempty"`

Error string `json:"Error,omitempty"` // Is set only in case of check failed caused by invoker problems

Statistics *JobResultStatistics `json:"Statistics"`
Statistics *JobResultStatistics `json:"Statistics,omitempty"`

InvokerStatus *invokerconn.Status `json:"InvokerStatus"`

Metrics *InvokerJobMetrics `json:"Metrics"`
}

type JobResultStatistics struct {
Expand All @@ -27,3 +30,13 @@ type JobResultStatistics struct {
ExitCode int `json:"ExitCode"`
// TODO: Add more statistics
}

type InvokerJobMetrics struct {
TestingWaitDuration time.Duration `json:"InvokerWaitDuration"`
TotalSandboxOccupation time.Duration `json:"TotalSandboxOccupation"`
ResourceWaitDuration time.Duration `json:"ResourceWaitDuration"`
FileActionsDuration time.Duration `json:"FileActionsDuration"`
ExecutionWaitDuration time.Duration `json:"ExecutionWaitDuration"`
ExecutionDuration time.Duration `json:"ExecutionDuration"`
SendResultDuration time.Duration `json:"SendResultDuration"`
}
103 changes: 103 additions & 0 deletions common/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package metrics

import (
"github.com/prometheus/client_golang/prometheus"
"testing_system/common/connectors/masterconn"
)

const (
invokerLabel = "invoker"
jobTypeLabel = "job_type"
)

type Collector struct {
Registerer *prometheus.Registry

InvokerJobResults *prometheus.CounterVec
InvokerTestingWaitDuration *prometheus.CounterVec
InvokerSandboxOccupationDuration *prometheus.CounterVec
InvokerResourceWaitDuration *prometheus.CounterVec
InvokerFileActionsDuration *prometheus.CounterVec
InvokerExecutionWaitDuration *prometheus.CounterVec
InvokerExecutionDuration *prometheus.CounterVec
InvokerSendResultDuration *prometheus.CounterVec
}

func NewCollector() *Collector {
c := &Collector{
Registerer: prometheus.NewRegistry(),
}
c.InvokerJobResults = c.createInvokerCounter(
"job_results_count",
"Number of job results received from invoker",
)

c.InvokerTestingWaitDuration = c.createInvokerCounter(
"testing_wait_duration_sum",
"Time submission waits for testing in invoker",
)

c.InvokerSandboxOccupationDuration = c.createInvokerCounter(
"sandbox_occupation_duration_sum",
"Total sandbox time for submission testing in invoker",
)

c.InvokerResourceWaitDuration = c.createInvokerCounter(
"resource_wait_duration_sum",
"Total time spent waiting for resources for submissions to load in invokers",
)

c.InvokerFileActionsDuration = c.createInvokerCounter(
"file_actions_duration_sum",
"Total time spent waiting for file copy to sandbox in invoker",
)

c.InvokerExecutionWaitDuration = c.createInvokerCounter(
"execution_wait_duration_sum",
"Total time spent waiting for execution of process on invoker when sandbox is set up",
)

c.InvokerExecutionDuration = c.createInvokerCounter(
"execution_duration_sum",
"Total time spent on executing processes in sandboxes",
)

c.InvokerSendResultDuration = c.createInvokerCounter(
"send_result_duration_sum",
"Total time spent on sending results from invoker to storage",
)
return c
}

func (c *Collector) createInvokerCounter(
name string,
help string,
) *prometheus.CounterVec {
counter := prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "ts",
Subsystem: "invoker",
Name: name,
Help: help,
},
[]string{invokerLabel, jobTypeLabel},
)
c.Registerer.MustRegister(counter)
return counter
}

func (c *Collector) NewJobResult(result *masterconn.InvokerJobResult) {
labels := prometheus.Labels{
invokerLabel: result.InvokerStatus.Address,
jobTypeLabel: result.Job.Type.String(),
}

c.InvokerJobResults.With(labels).Inc()
c.InvokerTestingWaitDuration.With(labels).Add(result.Metrics.TestingWaitDuration.Seconds())
c.InvokerSandboxOccupationDuration.With(labels).Add(result.Metrics.TotalSandboxOccupation.Seconds())
c.InvokerResourceWaitDuration.With(labels).Add(result.Metrics.ResourceWaitDuration.Seconds())
c.InvokerFileActionsDuration.With(labels).Add(result.Metrics.FileActionsDuration.Seconds())
c.InvokerExecutionWaitDuration.With(labels).Add(result.Metrics.ExecutionWaitDuration.Seconds())
c.InvokerExecutionDuration.With(labels).Add(result.Metrics.ExecutionDuration.Seconds())
c.InvokerSendResultDuration.With(labels).Add(result.Metrics.SendResultDuration.Seconds())
}
14 changes: 11 additions & 3 deletions common/testing_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"context"
"fmt"
"github.com/prometheus/client_golang/prometheus/promhttp"
"os/signal"
"runtime"
"slices"
Expand All @@ -12,16 +13,18 @@ import (
"testing_system/common/connectors/masterconn"
"testing_system/common/connectors/storageconn"
"testing_system/common/db"
"testing_system/common/metrics"
"testing_system/lib/logger"

"github.com/gin-gonic/gin"
"gorm.io/gorm"
)

type TestingSystem struct {
Config *config.Config
Router *gin.Engine
DB *gorm.DB
Config *config.Config
Router *gin.Engine
DB *gorm.DB
Metrics *metrics.Collector

MasterConn *masterconn.Connector
StorageConn *storageconn.Connector
Expand Down Expand Up @@ -54,6 +57,11 @@ func InitTestingSystem(configPath string) *TestingSystem {
ts.MasterConn = masterconn.NewConnector(ts.Config.MasterConnection)
ts.StorageConn = storageconn.NewConnector(ts.Config.StorageConnection)

ts.Metrics = metrics.NewCollector()
ts.Router.GET("/metrics", gin.WrapH(promhttp.HandlerFor(ts.Metrics.Registerer, promhttp.HandlerOpts{
ErrorLog: logger.CreateWriter(logger.LogLevelError, "[Prometheus]"),
})))

return ts
}

Expand Down
8 changes: 0 additions & 8 deletions data/compile/config.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions data/compile/scripts/g++.sh.tmpl

This file was deleted.

7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/gin-gonic/gin v1.10.0
github.com/go-resty/resty/v2 v2.16.5
github.com/google/uuid v1.6.0
github.com/prometheus/client_golang v1.22.0
github.com/stretchr/testify v1.10.0
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
Expand All @@ -20,8 +21,10 @@ require (

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.13.2 // indirect
github.com/bytedance/sonic/loader v0.2.4 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
Expand Down Expand Up @@ -49,8 +52,12 @@ require (
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/swaggo/swag v1.16.4 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
Expand Down
18 changes: 16 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ=
github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
github.com/cenkalti/backoff/v5 v5.0.2 h1:rIfFVxEf1QsI7E1ZHfp/B4DF/6QBAUhmgkxc0H7Zss8=
github.com/cenkalti/backoff/v5 v5.0.2/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
Expand Down Expand Up @@ -41,8 +45,8 @@ github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptd
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -83,10 +87,20 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q=
github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
6 changes: 3 additions & 3 deletions invoker/check_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *JobPipelineState) generateCheckerRunConfig() error {

func (s *JobPipelineState) executeCheckerRunCommand() error {
s.executeWaitGroup.Add(1)
s.invoker.RunQueue <- s.runChecker
s.runProcess(s.runChecker)
s.executeWaitGroup.Wait()

if s.test.checkResult.Err != nil {
Expand Down Expand Up @@ -175,11 +175,11 @@ func (s *JobPipelineState) uploadTestRunResources() error {
func (s *JobPipelineState) uploadCheckerOutput() error {
checkerOutputRequest := &storageconn.Request{
Resource: resource.CheckerOutput,
SubmitID: uint64(s.job.Submission.ID),
SubmitID: uint64(s.job.submission.ID),
TestID: s.job.Test,
File: s.test.checkerOutputReader,
}
resp := s.invoker.TS.StorageConn.Upload(checkerOutputRequest)
resp := s.uploadResource(checkerOutputRequest)
if resp.Error != nil {
return fmt.Errorf("can not upload checker output to storage, error: %s", resp.Error.Error())
}
Expand Down
Loading
Loading