Skip to content

Commit e6a52a6

Browse files
committed
kk
1 parent 04a0376 commit e6a52a6

3 files changed

Lines changed: 60 additions & 4 deletions

File tree

‎crates/bin/docs_rs_web/src/config.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ pub struct Config {
3939
#[builder(default)]
4040
pub(crate) csp_report_only: bool,
4141

42+
/// Datadog graph embed URLs generated for a 400 × 200 viewport.
43+
/// Unset URLs hide the corresponding graphs on the build queue page.
44+
pub(crate) build_queue_length_graph_url: Option<String>,
45+
pub(crate) build_queue_wait_time_graph_url: Option<String>,
46+
4247
// Cache-Control header, for versioned URLs.
4348
// If both are absent, don't generate the header. If only one is present,
4449
// generate just that directive.
@@ -63,6 +68,10 @@ impl<S: State> ConfigBuilder<S> {
6368
.maybe_report_request_timeouts(maybe_env("DOCSRS_REPORT_REQUEST_TIMEOUTS")?)
6469
.maybe_random_crate_search_view_size(maybe_env("DOCSRS_RANDOM_CRATE_SEARCH_VIEW_SIZE")?)
6570
.maybe_csp_report_only(maybe_env("DOCSRS_CSP_REPORT_ONLY")?)
71+
.maybe_build_queue_length_graph_url(maybe_env("DOCSRS_BUILD_QUEUE_LENGTH_GRAPH_URL")?)
72+
.maybe_build_queue_wait_time_graph_url(maybe_env(
73+
"DOCSRS_BUILD_QUEUE_WAIT_TIME_GRAPH_URL",
74+
)?)
6675
.maybe_cache_control_stale_while_revalidate(maybe_env(
6776
"CACHE_CONTROL_STALE_WHILE_REVALIDATE",
6877
)?)

‎crates/bin/docs_rs_web/src/handlers/releases.rs‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,8 @@ struct BuildQueuePage {
768768
in_progress_builds: Vec<InProgressBuild>,
769769
expand_rebuild_queue: bool,
770770
show_length_warning: bool,
771+
queue_length_graph_url: Option<String>,
772+
queue_wait_time_graph_url: Option<String>,
771773
}
772774

773775
impl_axum_webpage! { BuildQueuePage }
@@ -786,6 +788,7 @@ pub(crate) struct BuildQueueParams {
786788
}
787789

788790
pub(crate) async fn build_queue_handler(
791+
State(config): State<Arc<Config>>,
789792
State(build_queue): State<Arc<AsyncBuildQueue>>,
790793
Extension(csp): Extension<Arc<Csp>>,
791794
mut conn: DbConnection,
@@ -849,7 +852,11 @@ pub(crate) async fn build_queue_handler(
849852
}
850853
});
851854

852-
csp.allow_datadog_frame();
855+
if config.build_queue_length_graph_url.is_some()
856+
|| config.build_queue_wait_time_graph_url.is_some()
857+
{
858+
csp.allow_datadog_frame();
859+
}
853860

854861
Ok(BuildQueuePage {
855862
description: "crate documentation scheduled to build & deploy",
@@ -858,6 +865,8 @@ pub(crate) async fn build_queue_handler(
858865
in_progress_builds,
859866
expand_rebuild_queue: params.expand.is_some(),
860867
show_length_warning,
868+
queue_length_graph_url: config.build_queue_length_graph_url.clone(),
869+
queue_wait_time_graph_url: config.build_queue_wait_time_graph_url.clone(),
861870
})
862871
}
863872

@@ -886,6 +895,38 @@ mod tests {
886895
use std::str::FromStr;
887896
use test_case::test_case;
888897

898+
#[test_case(false, false)]
899+
#[test_case(true, false)]
900+
#[test_case(false, true)]
901+
#[test_case(true, true)]
902+
fn test_build_queue_optional_graphs(length: bool, wait_time: bool) {
903+
let url = "https://app.datadoghq.com/graph/embed?token=test&legend=true";
904+
let mut page = BuildQueuePage {
905+
description: "test",
906+
queue: Vec::new(),
907+
rebuild_queue: Vec::new(),
908+
in_progress_builds: Vec::new(),
909+
expand_rebuild_queue: false,
910+
show_length_warning: false,
911+
queue_length_graph_url: length.then(|| url.to_owned()),
912+
queue_wait_time_graph_url: wait_time.then(|| url.to_owned()),
913+
};
914+
let html =
915+
kuchikiki::parse_html().one(page.render_with_csp_nonce("test-nonce".into()).unwrap());
916+
let frames: Vec<_> = html
917+
.select(".build-queue-metrics iframe")
918+
.unwrap()
919+
.collect();
920+
assert_eq!(frames.len(), usize::from(length) + usize::from(wait_time));
921+
for frame in frames {
922+
assert_eq!(frame.attributes.borrow().get("src"), Some(url));
923+
}
924+
assert_eq!(
925+
html.select(".build-queue-layout").unwrap().count(),
926+
usize::from(length || wait_time)
927+
);
928+
}
929+
889930
#[test]
890931
fn test_release_list_with_incomplete_release_and_successful_build() {
891932
async_wrapper(|env| async move {

‎crates/bin/docs_rs_web/templates/releases/build_queue.html‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</div>
2828
{%- endif %}
2929

30-
<div class="build-queue-layout">
30+
<div class="{% if queue_length_graph_url.is_some() || queue_wait_time_graph_url.is_some() %}build-queue-layout{% endif %}">
3131
<div class="recent-releases-container">
3232
<div class="release">
3333
<strong>Currently being built</strong>
@@ -128,24 +128,30 @@
128128
</ol>
129129
{%- endif -%}
130130
</div>
131+
{% if queue_length_graph_url.is_some() || queue_wait_time_graph_url.is_some() %}
131132
<aside class="build-queue-metrics" aria-label="Build metrics">
133+
{% if let Some(url) = queue_length_graph_url %}
132134
<iframe
133135
class="build-metrics-graph"
134-
src="https://app.datadoghq.com/graph/embed?token=f0fcea6ecf4c6e24aee42bf3588050c6708bd6cf92f1a2eae770997a83f0f60d&amp;height=200&amp;width=400&amp;legend=false"
136+
src="{{ url }}"
135137
title="Queue length graph"
136138
width="400"
137139
height="200"
138140
frameborder="0"
139141
></iframe>
142+
{% endif %}
143+
{% if let Some(url) = queue_wait_time_graph_url %}
140144
<iframe
141145
class="build-metrics-graph"
142-
src="https://app.datadoghq.com/graph/embed?token=5a41fdbad1daf9e6f9e95f66aa09b24ae0efb40baf11930af0342693ce97ea77&amp;height=200&amp;width=400&amp;legend=true"
146+
src="{{ url }}"
143147
title="Queue waiting time graph"
144148
width="400"
145149
height="200"
146150
frameborder="0"
147151
></iframe>
152+
{% endif %}
148153
</aside>
154+
{% endif %}
149155
</div>
150156
</div>
151157
{%- endblock body -%}

0 commit comments

Comments
 (0)