Skip to content

Commit 604eae6

Browse files
chore(code): delete unused code (#1452)
1 parent f0ff687 commit 604eae6

File tree

6 files changed

+57
-133
lines changed

6 files changed

+57
-133
lines changed

agent-control/src/agent_type/definition.rs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use super::{
1212
variable::definition::{VariableDefinition, VariableDefinitionTree},
1313
};
1414

15-
use crate::agent_control::defaults::default_capabilities;
1615
use crate::values::yaml_config::YAMLConfig;
17-
use opamp_client::operation::capabilities::Capabilities;
1816
use serde::Deserialize;
1917
use std::collections::HashMap;
2018
use tracing::warn;
@@ -50,7 +48,6 @@ pub struct AgentType {
5048
pub agent_type_id: AgentTypeID,
5149
pub variables: VariableTree,
5250
pub runtime_config: Runtime,
53-
capabilities: Capabilities,
5451
}
5552

5653
impl AgentType {
@@ -59,17 +56,8 @@ impl AgentType {
5956
agent_type_id: metadata,
6057
variables,
6158
runtime_config,
62-
capabilities: default_capabilities(), // TODO: can capabilities be set in AgentTypeDefinition?
6359
}
6460
}
65-
66-
pub fn get_variables(&self) -> Variables {
67-
self.variables.clone().flatten()
68-
}
69-
70-
pub fn get_capabilities(&self) -> Capabilities {
71-
self.capabilities
72-
}
7361
}
7462

7563
/// Flexible tree-like structure that contains variables definitions, that can later be changed by the end user via [`YAMLConfig`].
@@ -240,10 +228,6 @@ pub mod tests {
240228
build_agent_type(definition, environment).unwrap()
241229
}
242230

243-
pub fn set_capabilities(&mut self, capabilities: Capabilities) {
244-
self.capabilities = capabilities
245-
}
246-
247231
/// Retrieve the `variables` field of the agent type at the specified key, if any.
248232
pub fn get_variable(self, path: String) -> Option<VariableDefinition> {
249233
self.variables.flatten().get(&path).cloned()
@@ -449,25 +433,22 @@ status_server_port: 8004
449433
input_agent_type.fill_variables(GIVEN_NEWRELIC_INFRA_USER_CONFIG_YAML);
450434

451435
// Then, we expect the corresponding final values.
452-
let expected_config_3: TrivialValue = HashMap::from([
436+
let expected_config_3 = TrivialValue::MapStringString(HashMap::from([
453437
("log_level".to_string(), "trace".to_string()),
454438
("forward".to_string(), "true".to_string()),
455-
])
456-
.into();
439+
]));
457440
// File with default
458-
let expected_config_2: TrivialValue = FilePathWithContent::new(
441+
let expected_config_2 = TrivialValue::File(FilePathWithContent::new(
459442
"config2.yml".into(),
460443
"license_key: abc123\nstaging: true\n".to_string(),
461-
)
462-
.into();
444+
));
463445
// File with values
464-
let expected_config: TrivialValue = FilePathWithContent::new(
446+
let expected_config = TrivialValue::File(FilePathWithContent::new(
465447
"config.yml".into(),
466448
"license_key: abc124\nstaging: false\n".to_string(),
467-
)
468-
.into();
449+
));
469450
// MapStringFile
470-
let expected_integrations: TrivialValue = HashMap::from([
451+
let expected_integrations = TrivialValue::MapStringFile(HashMap::from([
471452
(
472453
"kafka.conf".to_string(),
473454
FilePathWithContent::new(
@@ -479,10 +460,9 @@ status_server_port: 8004
479460
"redis.yml".to_string(),
480461
FilePathWithContent::new("integrations.d".into(), "user: redis\n".to_string()),
481462
),
482-
])
483-
.into();
463+
]));
484464
// Number
485-
let expected_status_server: TrivialValue = Number::from(8004).into();
465+
let expected_status_server = TrivialValue::Number(Number::from(8004));
486466

487467
assert_eq!(
488468
expected_config_3,

agent-control/src/agent_type/runtime_config/restart_policy.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ pub(super) const DEFAULT_BACKOFF_LAST_RETRY_INTERVAL: Duration = Duration::from_
4343
pub struct BackoffDelay(#[serde(deserialize_with = "deserialize_duration")] Duration);
4444

4545
impl BackoffDelay {
46-
pub fn new(value: Duration) -> Self {
47-
Self(value)
48-
}
49-
5046
pub fn from_secs(value: u64) -> Self {
5147
Self(Duration::from_secs(value))
5248
}
@@ -57,10 +53,6 @@ impl BackoffDelay {
5753
pub struct BackoffLastRetryInterval(#[serde(deserialize_with = "deserialize_duration")] Duration);
5854

5955
impl BackoffLastRetryInterval {
60-
pub fn new(value: Duration) -> Self {
61-
Self(value)
62-
}
63-
6456
pub fn from_secs(value: u64) -> Self {
6557
Self(Duration::from_secs(value))
6658
}

agent-control/src/agent_type/templates.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,12 @@ fn template_yaml_value_string(
187187
#[cfg(test)]
188188
mod tests {
189189
use super::*;
190-
use crate::agent_type::variable::kind_value::KindValue;
190+
use crate::agent_type::trivial_value::FilePathWithContent;
191+
use crate::agent_type::variable::kind_value::{KindValue, KindValueWithPath};
191192
use assert_matches::assert_matches;
192193
use rstest::rstest;
193194
use serde_yaml::Number;
195+
use std::collections::HashMap;
194196

195197
#[rstest]
196198
#[case::multiline_indent_line("\nline1\nline2\n", "|indent 1", "\n line1\n line2\n ")]
@@ -739,4 +741,46 @@ mod tests {
739741
AgentTypeError::MissingTemplateKey(s) => s);
740742
assert_eq!("does.not.exists".to_string(), key);
741743
}
744+
745+
impl From<KindValue<String>> for Kind {
746+
fn from(kind_value: KindValue<String>) -> Self {
747+
Kind::String(kind_value)
748+
}
749+
}
750+
751+
impl From<KindValue<bool>> for Kind {
752+
fn from(kind_value: KindValue<bool>) -> Self {
753+
Kind::Bool(kind_value)
754+
}
755+
}
756+
757+
impl From<KindValue<Number>> for Kind {
758+
fn from(kind_value: KindValue<Number>) -> Self {
759+
Kind::Number(kind_value)
760+
}
761+
}
762+
763+
impl From<KindValueWithPath<FilePathWithContent>> for Kind {
764+
fn from(kind_value: KindValueWithPath<FilePathWithContent>) -> Self {
765+
Kind::File(kind_value)
766+
}
767+
}
768+
769+
impl From<KindValue<HashMap<String, String>>> for Kind {
770+
fn from(kind_value: KindValue<HashMap<String, String>>) -> Self {
771+
Kind::MapStringString(kind_value)
772+
}
773+
}
774+
775+
impl From<KindValueWithPath<HashMap<String, FilePathWithContent>>> for Kind {
776+
fn from(kind_value: KindValueWithPath<HashMap<String, FilePathWithContent>>) -> Self {
777+
Kind::MapStringFile(kind_value)
778+
}
779+
}
780+
781+
impl From<KindValue<serde_yaml::Value>> for Kind {
782+
fn from(kind_value: KindValue<serde_yaml::Value>) -> Self {
783+
Kind::Yaml(kind_value)
784+
}
785+
}
742786
}

agent-control/src/agent_type/trivial_value.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,6 @@ pub enum TrivialValue {
2323
MapStringFile(Map<String, FilePathWithContent>),
2424
}
2525

26-
impl From<String> for TrivialValue {
27-
fn from(s: String) -> Self {
28-
TrivialValue::String(s)
29-
}
30-
}
31-
32-
impl From<FilePathWithContent> for TrivialValue {
33-
fn from(file: FilePathWithContent) -> Self {
34-
TrivialValue::File(file)
35-
}
36-
}
37-
38-
impl From<serde_yaml::Value> for TrivialValue {
39-
fn from(yaml: serde_yaml::Value) -> Self {
40-
TrivialValue::Yaml(yaml)
41-
}
42-
}
43-
44-
impl From<bool> for TrivialValue {
45-
fn from(b: bool) -> Self {
46-
TrivialValue::Bool(b)
47-
}
48-
}
49-
50-
impl From<serde_yaml::Number> for TrivialValue {
51-
fn from(n: serde_yaml::Number) -> Self {
52-
TrivialValue::Number(n)
53-
}
54-
}
55-
56-
impl From<Map<String, String>> for TrivialValue {
57-
fn from(map: Map<String, String>) -> Self {
58-
TrivialValue::MapStringString(map)
59-
}
60-
}
61-
62-
impl From<Map<String, FilePathWithContent>> for TrivialValue {
63-
fn from(map: Map<String, FilePathWithContent>) -> Self {
64-
TrivialValue::MapStringFile(map)
65-
}
66-
}
67-
6826
impl TrivialValue {
6927
/// If the trivial value is a yaml, it returns a copy the corresponding [serde_yaml::Value], returns None otherwise.
7028
pub fn to_yaml_value(&self) -> Option<serde_yaml::Value> {

agent-control/src/agent_type/variable/kind.rs

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use std::{collections::HashMap, path::PathBuf};
2-
3-
use serde::{Deserialize, Serialize};
4-
1+
use super::kind_value::{KindValue, KindValueWithPath};
52
use crate::agent_type::{
63
error::AgentTypeError,
74
trivial_value::{FilePathWithContent, TrivialValue},
85
};
9-
10-
use super::kind_value::{KindValue, KindValueWithPath};
6+
use serde::{Deserialize, Serialize};
7+
use std::{collections::HashMap, path::PathBuf};
118

129
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
1310
#[serde(tag = "type")]
@@ -28,49 +25,6 @@ pub enum Kind {
2825
Yaml(KindValue<serde_yaml::Value>),
2926
}
3027

31-
/// Conversions from KindValue<T> to Kind
32-
impl From<KindValue<String>> for Kind {
33-
fn from(kind_value: KindValue<String>) -> Self {
34-
Kind::String(kind_value)
35-
}
36-
}
37-
38-
impl From<KindValue<bool>> for Kind {
39-
fn from(kind_value: KindValue<bool>) -> Self {
40-
Kind::Bool(kind_value)
41-
}
42-
}
43-
44-
impl From<KindValue<serde_yaml::Number>> for Kind {
45-
fn from(kind_value: KindValue<serde_yaml::Number>) -> Self {
46-
Kind::Number(kind_value)
47-
}
48-
}
49-
50-
impl From<KindValueWithPath<FilePathWithContent>> for Kind {
51-
fn from(kind_value: KindValueWithPath<FilePathWithContent>) -> Self {
52-
Kind::File(kind_value)
53-
}
54-
}
55-
56-
impl From<KindValue<HashMap<String, String>>> for Kind {
57-
fn from(kind_value: KindValue<HashMap<String, String>>) -> Self {
58-
Kind::MapStringString(kind_value)
59-
}
60-
}
61-
62-
impl From<KindValueWithPath<HashMap<String, FilePathWithContent>>> for Kind {
63-
fn from(kind_value: KindValueWithPath<HashMap<String, FilePathWithContent>>) -> Self {
64-
Kind::MapStringFile(kind_value)
65-
}
66-
}
67-
68-
impl From<KindValue<serde_yaml::Value>> for Kind {
69-
fn from(kind_value: KindValue<serde_yaml::Value>) -> Self {
70-
Kind::Yaml(kind_value)
71-
}
72-
}
73-
7428
/// The below methods are mostly concerned with delegating to the inner type on each `Kind` variant.
7529
/// It's a lot of boilerplate, but declarative and straight-forward.
7630
impl Kind {

agent-control/src/event.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ impl SubAgentEvent {
5050
pub fn new_health(agent_identity: AgentIdentity, health: HealthWithStartTime) -> Self {
5151
Self::HealthUpdated(agent_identity, health)
5252
}
53-
54-
pub fn new_agent_started(agent_identity: AgentIdentity, started_time: SystemTime) -> Self {
55-
Self::SubAgentStarted(agent_identity, started_time)
56-
}
5753
}
5854

5955
/// Defines internal events for the AgentControl component

0 commit comments

Comments
 (0)