Skip to main content

loadmaster_probe/
known.rs

1//! Known upstream issues: when a failure matches a curated signature, the probe prints the
2//! issue URL. The curated list is `known_issues.toml` next to the fixtures.
3
4use serde::{Deserialize, Serialize};
5
6use crate::detect::Detected;
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(deny_unknown_fields)]
10pub struct KnownIssue {
11    /// Failure class, e.g. `call_in_content`.
12    pub failure: String,
13    /// Runtime it applies to; any when absent.
14    #[serde(default, skip_serializing_if = "Option::is_none")]
15    pub runtime: Option<String>,
16    /// Case-insensitive substring of the model name; any when absent.
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    pub model: Option<String>,
19    pub url: String,
20    pub note: String,
21}
22
23#[derive(Debug, Default, Deserialize)]
24#[serde(deny_unknown_fields)]
25struct File {
26    #[serde(default)]
27    issue: Vec<KnownIssue>,
28}
29
30pub fn parse(text: &str) -> Result<Vec<KnownIssue>, String> {
31    toml::from_str::<File>(text)
32        .map(|f| f.issue)
33        .map_err(|e| e.to_string())
34}
35
36/// The curated list shipped with loadmaster.
37pub fn builtin() -> Vec<KnownIssue> {
38    parse(include_str!("../fixtures/known_issues.toml")).expect("built-in known_issues.toml parses")
39}
40
41pub fn matches(k: &KnownIssue, failure: &str, d: &Detected, model: &str) -> bool {
42    k.failure == failure
43        && k.runtime.as_ref().is_none_or(|r| *r == d.runtime)
44        && k.model
45            .as_ref()
46            .is_none_or(|m| model.to_ascii_lowercase().contains(&m.to_ascii_lowercase()))
47}