Skip to content

Commit b847f2c

Browse files
committed
feat: [#246] add GrafanaRequiresPrometheus error variant
- Add ConfigError::GrafanaRequiresPrometheus variant with clear error message - Implement comprehensive help() method with actionable guidance - Provide two fix options: enable Prometheus or disable Grafana - Include JSON configuration examples in help text - Add unit test validating error message and help content This error will be used during environment configuration validation to enforce the dependency that Grafana requires Prometheus to be enabled.
1 parent 503df82 commit b847f2c

File tree

1 file changed

+41
-0
lines changed
  • src/application/command_handlers/create/config

1 file changed

+41
-0
lines changed

src/application/command_handlers/create/config/errors.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ pub enum CreateConfigError {
9797
#[source]
9898
source: std::io::Error,
9999
},
100+
101+
/// Grafana requires Prometheus to be enabled
102+
#[error("Grafana requires Prometheus to be enabled")]
103+
GrafanaRequiresPrometheus,
100104
}
101105

102106
impl CreateConfigError {
@@ -366,6 +370,31 @@ impl CreateConfigError {
366370
3. Ensure the file is not open in another application\n\
367371
4. Check if antivirus software is blocking file creation"
368372
}
373+
Self::GrafanaRequiresPrometheus => {
374+
"Grafana requires Prometheus to be enabled.\n\
375+
\n\
376+
Grafana is a visualization tool that displays metrics collected by Prometheus.\n\
377+
It cannot function without Prometheus as its data source.\n\
378+
\n\
379+
Current configuration issue:\n\
380+
- Grafana section is present in your configuration\n\
381+
- Prometheus section is absent or disabled\n\
382+
\n\
383+
Fix (choose one):\n\
384+
\n\
385+
Option 1 - Enable Prometheus:\n\
386+
Add a prometheus section to your environment configuration:\n\
387+
\n\
388+
\"prometheus\": {\n\
389+
\"scrape_interval\": 15\n\
390+
}\n\
391+
\n\
392+
Option 2 - Disable Grafana:\n\
393+
Remove the grafana section from your environment configuration\n\
394+
\n\
395+
Note: Prometheus can run independently without Grafana, but Grafana\n\
396+
requires Prometheus to be enabled."
397+
}
369398
}
370399
}
371400
}
@@ -508,4 +537,16 @@ mod tests {
508537
assert!(error.help().contains("permissions"));
509538
assert!(error.help().contains("disk space"));
510539
}
540+
541+
#[test]
542+
fn it_should_return_error_when_grafana_requires_prometheus() {
543+
let error = CreateConfigError::GrafanaRequiresPrometheus;
544+
545+
assert!(error.to_string().contains("Grafana requires Prometheus"));
546+
assert!(error.help().contains("Grafana section is present"));
547+
assert!(error.help().contains("Prometheus section is absent"));
548+
assert!(error.help().contains("Add a prometheus section"));
549+
assert!(error.help().contains("Remove the grafana section"));
550+
assert!(error.help().contains("scrape_interval"));
551+
}
511552
}

0 commit comments

Comments
 (0)