feat(healthcheck): remove joj3-check
All checks were successful
submodules sync / sync (push) Successful in 32s
build / build (push) Successful in 1m11s
build / trigger-build-image (push) Successful in 6s

This commit is contained in:
张泊明518370910136 2025-02-01 04:59:16 -05:00
parent 1bc539a80f
commit 1bbc589897
GPG Key ID: D47306D7062CDA9D
3 changed files with 3 additions and 140 deletions

View File

@ -9,7 +9,6 @@ import (
"strings"
"github.com/joint-online-judge/JOJ3/cmd/joj3/env"
"github.com/joint-online-judge/JOJ3/internal/conf"
"github.com/joint-online-judge/JOJ3/pkg/healthcheck"
)
@ -57,19 +56,7 @@ func init() {
flag.StringVar(&checkFileNameList, "checkFileNameList", "", "comma-separated list of files to check")
flag.StringVar(&checkFileSumList, "checkFileSumList", "", "comma-separated list of expected checksums")
parseMultiValueFlag(&metaFile, "meta", "meta files to check")
flag.StringVar(&confPath, "confPath", "", "path to conf file for teapot check")
}
func prepareTeapotCheck() (
confObj *conf.Conf, groups []string, err error,
) {
confObj, err = conf.ParseConfFile(confPath)
if err != nil {
slog.Error("parse conf", "error", err)
return
}
groups = strings.Split(os.Getenv(env.Groups), ",")
return
flag.StringVar(&confPath, "confPath", "", "path to conf file for teapot check") // TODO: remove me
}
func main() {
@ -86,14 +73,9 @@ func main() {
"checkFileSumList", checkFileSumList,
"meta", metaFile,
)
var err error
confObj, groups, err := prepareTeapotCheck()
if err != nil {
slog.Error("prepare teapot check", "error", err)
confObj = nil
}
groups := strings.Split(os.Getenv(env.Groups), ",")
res := healthcheck.All(
confObj, rootDir, checkFileNameList, checkFileSumList,
rootDir, checkFileNameList, checkFileSumList,
groups, metaFile, repoSize,
)
jsonRes, err := json.Marshal(res)

View File

@ -2,8 +2,6 @@ package healthcheck
import (
"fmt"
"github.com/joint-online-judge/JOJ3/internal/conf"
)
type Result struct {
@ -12,21 +10,11 @@ type Result struct {
}
func All(
confObj *conf.Conf,
rootDir, checkFileNameList, checkFileSumList string,
groups, metaFile []string,
repoSize float64,
) (res Result) {
var err error
if confObj != nil {
output, err := TeapotCheck(confObj, groups)
if err != nil {
res.Msg += fmt.Sprintf("### Teapot Check Failed:\n%s\n", output)
res.Failed = true
} else {
res.Msg += fmt.Sprintf("### Teapot Check Result:\n%s\n", output)
}
}
err = RepoSize(repoSize)
if err != nil {
res.Msg += fmt.Sprintf("### Repo Size Check Failed:\n%s\n", err.Error())

View File

@ -1,107 +0,0 @@
package healthcheck
import (
"bytes"
"encoding/json"
"fmt"
"log/slog"
"os"
"os/exec"
"strings"
"github.com/joint-online-judge/JOJ3/internal/conf"
)
type CheckResult struct {
Name string `json:"name"`
SubmitCount int `json:"submit_count"`
MaxCount int `json:"max_count"`
TimePeriod int `json:"time_period"`
}
func runTeapot(conf *conf.Conf) (checkResults []CheckResult, err error) {
os.Setenv("LOG_FILE_PATH", conf.Teapot.LogPath)
var formattedGroups []string
for _, group := range conf.Teapot.Groups {
groupConfig := fmt.Sprintf("%s=%d:%d",
group.Name, group.MaxCount, group.TimePeriodHour)
formattedGroups = append(formattedGroups, groupConfig)
}
args := []string{
"joj3-check", conf.Teapot.EnvFilePath,
conf.Teapot.GradingRepoName,
conf.Teapot.ScoreboardPath,
"--group-config", strings.Join(formattedGroups, ","),
}
var stdoutBuf, stderrBuf bytes.Buffer
cmd := exec.Command("joint-teapot", args...) // #nosec G204
cmd.Stdout = &stdoutBuf
cmd.Stderr = &stderrBuf
err = cmd.Run()
if err != nil {
slog.Error("teapot check args", "args", args)
slog.Error("teapot check exec",
"stdout", stdoutBuf.String(), "stderr", stderrBuf.String())
slog.Error("teapot check exec", "error", err)
return
}
if err = json.Unmarshal(stdoutBuf.Bytes(), &checkResults); err != nil {
slog.Error("unmarshal teapot check result", "error", err,
"stdout", stdoutBuf.String())
return
}
slog.Info("teapot check result", "result", checkResults)
return
}
func generateOutput(
checkResults []CheckResult,
groups []string,
) (comment string, err error) {
if len(checkResults) == 0 {
return
}
for _, checkResult := range checkResults {
useGroup := false
if checkResult.Name != "" {
comment += fmt.Sprintf("keyword `%s` ", checkResult.Name)
} else {
useGroup = true
}
for _, group := range groups {
if strings.EqualFold(group, checkResult.Name) {
useGroup = true
break
}
}
comment += fmt.Sprintf(
"in last %d hour(s): submit count %d, max count %d",
checkResult.TimePeriod,
checkResult.SubmitCount,
checkResult.MaxCount,
)
if useGroup && checkResult.SubmitCount+1 > checkResult.MaxCount {
err = fmt.Errorf(
"keyword `%s` submit count exceeded",
checkResult.Name,
)
comment += ", exceeded"
}
comment += "\n"
}
return
}
func TeapotCheck(conf *conf.Conf, groups []string) (output string, err error) {
checkResults, err := runTeapot(conf)
if err != nil {
slog.Error("teapot check", "error", err)
return
}
output, err = generateOutput(checkResults, groups)
if err != nil {
slog.Error("generate output", "error", err)
return
}
return
}