Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rover-client): properly send validation period config #738

Merged
merged 1 commit into from
Aug 17, 2021
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
18 changes: 9 additions & 9 deletions crates/rover-client/src/operations/graph/check/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ impl From<GraphCheckInput> for MutationVariables {
type MutationConfig = graph_check_mutation::HistoricQueryParameters;
impl From<CheckConfig> for MutationConfig {
fn from(input: CheckConfig) -> Self {
let (from, to) = match input.validation_period {
Some(validation_period) => (
Some(validation_period.from.to_string()),
Some(validation_period.to.to_string()),
),
None => (None, None),
};
Self {
queryCountThreshold: input.query_count_threshold,
queryCountThresholdPercentage: input.query_count_threshold_percentage,
from: Some(
input
.validation_period
.clone()
.unwrap_or_default()
.from
.to_string(),
),
to: Some(input.validation_period.unwrap_or_default().to.to_string()),
from,
to,
// we don't support configuring these, but we can't leave them out
excludedClients: None,
ignoredOperations: None,
Expand Down
48 changes: 23 additions & 25 deletions crates/rover-client/src/operations/subgraph/check/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,30 @@ impl From<SubgraphCheckInput> for MutationVariables {
sdl: Some(input.proposed_schema),
hash: None,
},
config: MutationConfig {
queryCountThreshold: input.config.query_count_threshold,
queryCountThresholdPercentage: input.config.query_count_threshold_percentage,
from: Some(
input
.config
.validation_period
.clone()
.unwrap_or_default()
.from
.to_string(),
),
to: Some(
input
.config
.validation_period
.unwrap_or_default()
.to
.to_string(),
),
// we don't support configuring these, but we can't leave them out
excludedClients: None,
ignoredOperations: None,
includedVariants: None,
},
config: input.config.into(),
git_context: input.git_context.into(),
}
}
}

impl From<CheckConfig> for MutationConfig {
fn from(input: CheckConfig) -> Self {
let (from, to) = match input.validation_period {
Some(validation_period) => (
Some(validation_period.from.to_string()),
Some(validation_period.to.to_string()),
),
None => (None, None),
};
Self {
queryCountThreshold: input.query_count_threshold,
queryCountThresholdPercentage: input.query_count_threshold_percentage,
from,
to,
// we don't support configuring these, but we can't leave them out
excludedClients: None,
ignoredOperations: None,
includedVariants: None,
}
}
}
35 changes: 22 additions & 13 deletions crates/rover-client/src/shared/check_response.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::cmp::Ordering;
use std::fmt::{self};
use std::fmt::{self, Display};
use std::str::FromStr;

use crate::shared::GraphRef;
Expand Down Expand Up @@ -153,10 +153,10 @@ pub struct CheckConfig {
pub validation_period: Option<ValidationPeriod>,
}

#[derive(Debug, PartialEq, Eq, Serialize, Default, Clone)]
#[derive(Debug, PartialEq, Eq, Serialize, Clone)]
pub struct ValidationPeriod {
pub from: i64,
pub to: i64,
pub from: Period,
pub to: Period,
}

// Validation period is parsed as human readable time.
Expand All @@ -171,16 +171,25 @@ impl FromStr for ValidationPeriod {
};
let duration = humantime::parse_duration(period)?;

let from = duration.as_secs() as i64;
let from = -from;

let to = 0;

Ok(ValidationPeriod {
// search "from" a negative time window
from: -from,
// search "to" now (-0) seconds
to: -to,
from: Period::Past(duration.as_secs() as i64),
to: Period::Now,
})
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub enum Period {
Now,
Past(i64),
}

impl Display for Period {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let period = match &self {
Period::Now => "-0".to_string(),
Period::Past(seconds) => (-seconds).to_string(),
};
write!(f, "{}", period)
}
}
Empty file removed subgraphs/reviews.graphql
Empty file.