Skip to content

Commit

Permalink
Fix submit status NA when running (#93)
Browse files Browse the repository at this point in the history
* hide contest submission and private problem submission in global list.

* Follow OpenTelemetry Semantic Conventions

* Fix upstream connection span not attach to parent span

* Fix panic on running submit state(assuming none nullable column)
  • Loading branch information
Eason0729 authored Sep 11, 2024
1 parent b3dac66 commit c9631d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
26 changes: 14 additions & 12 deletions backend/src/controller/judger/route/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ use std::{
use crossbeam_queue::SegQueue;
use dashmap::{DashMap, DashSet};
use tonic::{service::Interceptor, *};
use tracing::{debug_span, instrument, Instrument};
use tracing::{debug_span, instrument, Instrument, Span};
use uuid::Uuid;

use crate::config::{self, Judger as JudgerConfig};
use crate::config::{self, Judger as JudgeConfig};
use grpc::judger::{judger_client::*, *};

// TODO: add tracing

// about health score:
//
// health score is a number in range [-1,HEALTH_MAX_SCORE)
// Upstream with negitive health score is consider unhealthy, and should disconnect immediately
// Upstream with negative health score is consider unhealthy, and should disconnect immediately

/// Max score a health Upstream can reach
const HEALTH_MAX_SCORE: isize = 100;

/// Judger Client intercepted by BasicAuthInterceptor
/// Judge Client intercepted by BasicAuthInterceptor
type AuthJudgerClient = JudgerClient<
service::interceptor::InterceptedService<transport::Channel, BasicAuthInterceptor>,
>;
Expand All @@ -54,12 +54,12 @@ impl Interceptor for BasicAuthInterceptor {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
/// Info necessary to create connection, implement reuse logic
pub struct ConnectionDetail {
pub uri: String,
pub secret: Option<String>,
// TODO: reuse logic shouldn't be binded with connection creation logic
// TODO: reuse logic shouldn't be bound with connection creation logic
pub reuse: bool,
}

Expand Down Expand Up @@ -128,9 +128,10 @@ impl Drop for ConnGuard {
/// occupy future, should generally be spawn in a green thread
#[instrument(skip(router), level = "info")]
async fn discover<I: Routable + Send>(
config: JudgerConfig,
config: JudgeConfig,
router: Weak<Router>,
) -> Result<(), Error> {
let parent = Span::current();
let mut instance = I::new(config.clone())?;
loop {
match instance.discover().in_current_span().await {
Expand All @@ -141,7 +142,7 @@ async fn discover<I: Routable + Send>(
};
let uri = detail.uri.clone();
let (upstream, langs) = Upstream::new(detail).in_current_span().await?;
let _ = debug_span!("connected", uri = uri).entered();
let _ = debug_span!(parent: parent.clone(), "connected", uri = uri).entered();
for (uuid, lang) in langs.into_iter() {
router.langs.insert(lang);
loop {
Expand Down Expand Up @@ -175,8 +176,8 @@ pub struct Router {

impl Router {
// skip because config contain basic auth secret
#[instrument(name = "router_construct", level = "info", skip_all)]
pub fn new(config: Vec<JudgerConfig>) -> Result<Arc<Self>, Error> {
#[instrument(name = "router_construct", level = "debug", skip_all)]
pub fn new(config: Vec<JudgeConfig>) -> Result<Arc<Self>, Error> {
let self_ = Arc::new(Self {
routing_table: DashMap::default(),
langs: DashSet::default(),
Expand Down Expand Up @@ -235,6 +236,7 @@ pub struct Upstream {

impl Upstream {
/// create new Upstream
#[instrument(name = "connecting_upstream", err, level = "info")]
async fn new(detail: ConnectionDetail) -> Result<(Arc<Self>, Vec<(Uuid, LangInfo)>), Error> {
let mut client = detail.connect().await?;
let info = client.judger_info(()).await?;
Expand All @@ -245,7 +247,7 @@ impl Upstream {
let uuid = match Uuid::parse_str(&lang.lang_uid) {
Ok(x) => x,
Err(err) => {
log::warn!("invalid lang_uid from judger: {}", err);
log::warn!("invalid lang_uid from judge: {}", err);
continue;
}
};
Expand Down Expand Up @@ -304,7 +306,7 @@ where
// return new connection when available, will immediately retry true is returned
async fn route(&mut self) -> Result<RouteStatus, Error>;
/// create from config
fn new(config: JudgerConfig) -> Result<Self, Error>;
fn new(config: JudgeConfig) -> Result<Self, Error>;
}

/// wrapper for Routable(Error handling)
Expand Down
8 changes: 6 additions & 2 deletions backend/src/endpoint/submit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use futures::{FutureExt, TryFutureExt};

use crate::controller::judger::SubmitBuilder;
use crate::util::code::Code;
Expand All @@ -13,8 +14,11 @@ use tokio_stream::wrappers::ReceiverStream;

impl From<Model> for SubmitInfo {
fn from(value: Model) -> Self {
// TODO: solve devation and uncommitted submit!
let db_code: Code = value.status.unwrap().try_into().unwrap();
let db_code: Code = value
.status
.map(TryInto::try_into)
.flatten()
.unwrap_or_else(Code::Unknown);
SubmitInfo {
id: value.id,
upload_time: into_prost(value.upload_at),
Expand Down
2 changes: 1 addition & 1 deletion backend/src/util/code.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use grpc::backend::StateCode as BackendCode;
use grpc::judger::JudgerCode;

/// Stablized JudgeResponse Code, store in database
/// Stabilized JudgeResponse Code, store in database
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub enum Code {
Expand Down

0 comments on commit c9631d7

Please sign in to comment.