Skip to content

Commit ecac4fc

Browse files
authored
refactor: remove file vartypes and ConfigurationPersister (#1743)
* refactor: remove ConfigurationPersister * docs: replace file var types with filesystem * chore: cleanup commented code * refactor: remove Renderer trait * chore: remove commented-out code
1 parent 329a219 commit ecac4fc

File tree

24 files changed

+993
-2859
lines changed

24 files changed

+993
-2859
lines changed

agent-control/src/agent_control/error.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::agent_control::config_validator::DynamicConfigValidatorError;
55
use crate::agent_control::version_updater::updater::UpdaterError;
66
use crate::agent_type::agent_type_registry::AgentRepositoryError;
77
use crate::agent_type::error::AgentTypeError;
8-
use crate::agent_type::render::persister::config_persister::PersistError;
98
use crate::event::channel::EventPublisherError;
109
use crate::opamp::client_builder::OpAMPClientBuilderError;
1110
use crate::opamp::instance_id;
@@ -54,9 +53,6 @@ pub enum AgentError {
5453
#[error("{0}")]
5554
OpAMPStartedClient(#[from] StartedClientError),
5655

57-
#[error("error persisting agent config: {0}")]
58-
Persistence(#[from] PersistError),
59-
6056
#[error("error getting agent instance id: {0}")]
6157
GetInstanceID(#[from] instance_id::getter::GetterError),
6258

agent-control/src/agent_control/run/k8s.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use crate::agent_control::resource_cleaner::ResourceCleanerError;
1515
use crate::agent_control::resource_cleaner::k8s_garbage_collector::K8sGarbageCollector;
1616
use crate::agent_control::run::AgentControlRunner;
1717
use crate::agent_control::version_updater::k8s::K8sACUpdater;
18-
use crate::agent_type::render::persister::config_persister_file::ConfigurationPersisterFile;
19-
use crate::agent_type::render::renderer::TemplateRenderer;
18+
use crate::agent_type::render::TemplateRenderer;
2019
use crate::agent_type::variable::Variable;
2120
use crate::agent_type::version_config::{
2221
AGENT_CONTROL_VERSION_CHECKER_INITIAL_DELAY, VersionCheckerInterval,
@@ -141,9 +140,8 @@ impl AgentControlRunner {
141140
),
142141
]);
143142

144-
let template_renderer: TemplateRenderer<ConfigurationPersisterFile> =
145-
TemplateRenderer::default()
146-
.with_agent_control_variables(agent_control_variables.clone().into_iter());
143+
let template_renderer = TemplateRenderer::default()
144+
.with_agent_control_variables(agent_control_variables.clone().into_iter());
147145

148146
let mut secrets_providers = SecretsProviders::new()
149147
.with_env()

agent-control/src/agent_control/run/on_host.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use crate::agent_control::http_server::runner::Runner;
1111
use crate::agent_control::resource_cleaner::no_op::NoOpResourceCleaner;
1212
use crate::agent_control::run::AgentControlRunner;
1313
use crate::agent_control::version_updater::updater::NoOpUpdater;
14-
use crate::agent_type::render::persister::config_persister_file::ConfigurationPersisterFile;
15-
use crate::agent_type::render::renderer::TemplateRenderer;
14+
use crate::agent_type::render::TemplateRenderer;
1615
use crate::agent_type::variable::Variable;
1716
use crate::event::channel::pub_sub;
1817
use crate::health::noop::NoOpHealthChecker;
@@ -136,10 +135,6 @@ impl AgentControlRunner {
136135
let opamp_client_builder = opamp_client_builder.map(|b| b.with_startup_check_disabled());
137136

138137
let template_renderer = TemplateRenderer::default()
139-
.with_config_persister(
140-
ConfigurationPersisterFile::new(&self.base_paths.remote_dir),
141-
self.base_paths.remote_dir.clone(),
142-
)
143138
.with_agent_control_variables(agent_control_variables.clone().into_iter());
144139

145140
let mut secrets_providers = SecretsProviders::new().with_env();

agent-control/src/agent_type/README.md

Lines changed: 88 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Agent Type Definition is a YAML file that defines an agent's configuration and behavior. It consists of three main sections: metadata, deployment, and variables.
44

5-
By defining these three sections, developers can create a customizable and flexible agent type that can be used in various environments.
5+
By defining these three sections, developers can create a customizable and flexible agent type that can be used in various environments.
66

77
## Metadata
88

@@ -15,31 +15,30 @@ version: 0.0.1
1515
```
1616
1717
The metadata fields can't be empty:
18+
1819
* The name and namespace should:
19-
- Start by an alphabetical character.
20-
- Only encompass `alphanumeric characters`, `.`, `_` or `-`.
21-
- Be in lowercase.
20+
* Start by an alphabetical character.
21+
* Only encompass `alphanumeric characters`, `.`, `_` or `-`.
22+
* Be in lowercase.
2223
* The version field should adhere to [semantic versioning](https://semver.org/).
2324

2425
## Variables
2526

26-
The variables section allows developers to define variables that end users can set. These variables can adjust the agent's or system's configuration.
27+
The `variables` section allows developers to define variables that end users can set. These variables can adjust the agent's or system's configuration.
2728

2829
```yaml
2930
variables:
3031
common:
3132
config_agent:
3233
description: "Newrelic infra configuration"
33-
type: file
34+
type: yaml
3435
required: false
35-
default: ""
36-
file_path: "newrelic-infra.yml"
36+
default: {}
3737
config_integrations:
3838
description: "map of YAML configs for the OHIs"
39-
type: map[string]file
39+
type: map[string]yaml
4040
required: false
4141
default: {}
42-
file_path: "integrations.d"
4342
on_host:
4443
backoff_delay:
4544
description: "seconds until next retry if agent fails to start"
@@ -57,6 +56,7 @@ variables:
5756
```
5857

5958
Variables can be classified based on their applicable environments:
59+
6060
* `on_host`: Refers to variables utilized in on host environments.
6161
* `k8s`: Applies to variables used within Kubernetes clusters.
6262
* `common`: For variables that are environment-agnostic.
@@ -78,30 +78,24 @@ common:
7878

7979
All variables have a few common attributes:
8080

81-
* `description`: A brief description of the variable.This is useful for documentation purposes and can help others understand the purpose of the variable.
82-
* `type`: The data type of the variable. We support several data types, including `string`, `file`, `bool`, `yaml`, and more.
81+
* `description`: A brief description of the variable. This is useful for documentation purposes and can help others understand the purpose of the variable.
82+
* `type`: The data type of the variable. We support several data types, including `string`, `file`, `bool`, `yaml`, and more.
8383
* `variants`: Represents a defined list of acceptable values for the variable. Only values present in the variants list are considered valid.
8484
* `default`: The default value for the variable if no value is provided.
8585
* `required`: Whether the variable is mandatory to be provided or not.
8686

87-
Moreover, file type variables possess an additional attribute:
88-
* `file_path`: Indicates where the file(s) is located.
89-
90-
In terms of variable types, we currently support the following types listed [here](variable/kind.rs#L14):
87+
In terms of variable types, we currently support the following types listed in [this source file](./variable/variable_type.rs#L22):
9188

9289
* `string`: A string value, such as "Hello, world!"
9390
* `number`: An numeric value, such as 42 or 0.25
9491
* `boolean`: A boolean value, which can be either *true* or *false*
95-
* `file`: It represents a file in the filesystem.
9692
* `map[string]string`: A dictionary of key-value pairs, associating keys(string) and values(string).
97-
* `map[string]file`: A dictionary of key-value pairs, associating keys(string) and values(file). Files are stored in the specified folder.
9893
* `yaml`: The YAML type variable is used to handle multi-line strings that will be parsed as YAML such as Helm Charts values.
99-
100-
Note that `file` and `map[string]file` variable types can be used just for `on_host` environments. Files are not supported in Kubernetes.
94+
* `map[string]yaml`: Handles YAML values that guarantee their top-level fields are strings. Useful for defining file system entries for on-host.
10195

10296
## Deployment
10397

104-
The deployment section indicates how the agent should be executed and its health should be checked.
98+
The deployment section indicates how the agent should be executed and how its health should be checked.
10599

106100
Note you can reference the variables defined in the `variables` section using `${nr-var:variable_name}`. And this is valid for nested variables as well: following the example above, you would be able to use `${nr-var:log.info}`.
107101

@@ -123,7 +117,7 @@ multi_line_string: |
123117
${nr-var:yaml_variable | indent 2 }
124118
```
125119

126-
### OnHost Deployment
120+
### On Host Deployment
127121

128122
For on-host deployment, use the following format:
129123

@@ -158,7 +152,7 @@ In this section:
158152
* `health`: The measures used to check the health status of the agent.
159153
* `version`: The command used to check the version of the binary.
160154
* `executables`: This outlines the list of binaries the agent supervisor runs. Developers can define:
161-
- * `id`: Unique identifier for the exec used by the health checker.
155+
* * `id`: Unique identifier for the exec used by the health checker.
162156
* `path`: The location of the binary required.
163157
* `args`: The command-line arguments needed by the binary.
164158
* `env`: Specifies the required environment variables.
@@ -168,19 +162,19 @@ These diverse options offer extensive customization for your agent's deployment.
168162

169163
#### Restart Policy
170164

171-
`restart_policy` provides a set of instructions on how and when the agent process should be restarted. It's crucial for maintaining the agent's availability and reliability, particularly in case of unexpected failures or problems.
165+
`restart_policy` provides a set of instructions on how and when the agent process should be restarted. It's crucial for maintaining the agent's availability and reliability, particularly in case of unexpected failures or problems.
172166

173167
In the `backoff_strategy` we have:
174168

175-
* `type`: This field can take several forms - _fixed_, _linear_, or _exponential_. It determines the delay timing strategy between retries.
176-
* _fixed_: Constant delay interval between retries. This is the default type.
177-
* _linear_: Delay interval increases linearly after each retry.
178-
* _exponential_: Delay interval doubles after each retry.
179-
* `backoff_delay`: It defines the duration between retries when a restart is needed. This delay protects against aggressive restarts. Default is _2s_.
180-
* `max_retries`: This integer value defines the maximum number of retry attempts before exiting the retry mechanism and accepting the failure. Default is _0_.
181-
* `last_retry_interal`: This is used to store the duration of the last delay. It can especially be relevant in case of _linear_ or _exponential_ backoff strategies where each retry level has a different delay value. Default is _600_.
169+
* `type`: This field can take several forms - `fixed`, `linear`, or `exponential`. It determines the delay timing strategy between retries.
170+
* `fixed`: Constant delay interval between retries. This is the default type.
171+
* `linear`: Delay interval increases linearly after each retry.
172+
* `exponential`: Delay interval doubles after each retry.
173+
* `backoff_delay`: It defines the duration between retries when a restart is needed. This delay protects against aggressive restarts. Default is *2s*.
174+
* `max_retries`: This integer value defines the maximum number of retry attempts before exiting the retry mechanism and accepting the failure. Default is *0*.
175+
* `last_retry_interal`: This is used to store the duration of the last delay. It can especially be relevant in case of *linear* or *exponential* back-off strategies where each retry level has a different delay value. Default is *600*.
182176

183-
#### OnHost Health
177+
#### On Host Health
184178

185179
The `health` section in the deployment configuration is where you can specify how to monitor the health status of the agent. This is critical for maintaining the reliability of your agent and ensuring that it's functioning correctly. Here's how you can define it in the `executables` block:
186180

@@ -196,10 +190,10 @@ health:
196190

197191
In this configuration:
198192

199-
* `interval`: This parameter specifies the frequency at which health checks should be performed.
200-
* `timeout`: This is the maximum time the agent should wait for a health check response.
193+
* `interval`: This parameter specifies the frequency at which health checks should be performed.
194+
* `timeout`: This is the maximum time the agent should wait for a health check response.
201195
* `http`: This section is for when agents expose their status through an HTTP endpoint. If this method is used, the `path` and `port` should be specified.
202-
* `path`: This is the API endpoint for the health check. Typically it's a URI where the agent returns its current health status.
196+
* `path`: This is the API endpoint for the health check. Typically, it's a URI where the agent returns its current health status.
203197
* `port`: This is the port on which the agent's health check endpoint is listening.
204198
* `healthy_codes`: This is a list of the HTTP codes the SA will consider as valid ones.
205199

@@ -217,6 +211,7 @@ health:
217211
healthy_codes: [0]
218212
unhealthy_string: ".*(unhealthy|fatal|error).*"
219213
```
214+
220215
```yaml
221216
# ...
222217
health:
@@ -228,7 +223,7 @@ health:
228223
unhealthy_string: ".*(unhealthy|fatal|error).*"
229224
```
230225

231-
#### OnHost Version
226+
#### On Host Version
232227

233228
The `version` section in the deployment configuration is where you can specify how to obtain the version of the binary running. Here's how you can define it block:
234229

@@ -241,11 +236,10 @@ version:
241236

242237
In this configuration:
243238

244-
* `path`: Specifies the binary to run.
245-
* `args`: Specifies the arguments passed to the binary to get the version.
239+
* `path`: Specifies the binary to run.
240+
* `args`: Specifies the arguments passed to the binary to get the version.
246241
* `regex`: Optional field that specifies the regular expression to get the version from the output. When not used, the whole output will be used as the version.
247242

248-
249243
### Kubernetes Deployment
250244

251245
The Agent Control leverages [Flux](https://fluxcd.io/) to act as an operator running Helm commands (install, upgrade, delete) as needed based on the provided configurations.
@@ -383,65 +377,65 @@ This guideline shows how to build a custom agent type and integrate it with the
383377

384378
1. Create a file with the agent type definition
385379

386-
```yaml
387-
# namespace: newrelic, external, other
388-
namespace: external
389-
# name: reverse FQDN that uniquely identifies the agent type
390-
name: com.influxdata.telegraf
391-
# version: semver scheme
392-
version: 0.0.1
393-
394-
# variables:
395-
# common | on_host | k8s:
396-
# my_var_1:
397-
# description: "Variable description here"
398-
# type: file | string
399-
# required: true | false
400-
# default: "default value"
401-
# file_path: "persistence path"
402-
403-
variables:
404-
on_host:
405-
config_file:
406-
description: "Telegraf config file path"
407-
type: string
408-
required: false
409-
default: "/path/to/telegraf.conf"
410-
backoff_delay:
411-
description: "seconds until next retry if agent fails to start"
412-
type: string
413-
required: false
414-
default: 20s
415-
416-
deployment:
417-
on_host:
418-
executables:
419-
- id: telegraf
420-
path: /usr/bin/telegraf
421-
args: "--config ${nr-var:config_file}"
422-
env: ""
423-
restart_policy:
424-
backoff_strategy:
425-
type: fixed
426-
backoff_delay: ${nr-var:backoff_delay}
427-
```
380+
```yaml
381+
# namespace: newrelic, external, other
382+
namespace: external
383+
# name: reverse FQDN that uniquely identifies the agent type
384+
name: com.influxdata.telegraf
385+
# version: semver scheme
386+
version: 0.0.1
387+
388+
# variables:
389+
# common | on_host | k8s:
390+
# my_var_1:
391+
# description: "Variable description here"
392+
# type: string
393+
# required: false
394+
# default: "default value"
395+
396+
variables:
397+
on_host:
398+
config_file:
399+
description: "Telegraf config file path"
400+
type: string
401+
required: false
402+
default: "/path/to/telegraf.conf"
403+
backoff_delay:
404+
description: "seconds until next retry if agent fails to start"
405+
type: string
406+
required: false
407+
default: 20s
408+
409+
deployment:
410+
on_host:
411+
executables:
412+
- id: telegraf
413+
path: /usr/bin/telegraf
414+
args: "--config ${nr-var:config_file}"
415+
env: ""
416+
restart_policy:
417+
backoff_strategy:
418+
type: fixed
419+
backoff_delay: ${nr-var:backoff_delay}
420+
```
428421

429422
2. Copy the agent type definition to the folder `/etc/newrelic-agent-control/dynamic-agent-types`
430-
431423
3. Use the new type in the `agents` config for the agent control:
432-
```yaml
433-
# fleet_control:
434-
# ...
435424

436-
agents:
437-
my-telegraf-collector:
438-
agent_type: "external/com.influxdata.telegraf:0.0.1"
439-
```
425+
```yaml
426+
# fleet_control:
427+
# ...
428+
429+
agents:
430+
my-telegraf-collector:
431+
agent_type: "external/com.influxdata.telegraf:0.0.1"
432+
```
440433

441434
4. If any `required` variable has been defined in the type or any default value for variables needs to be customized, then define a `values.yaml` in `/etc/newrelic-agent-control/fleet/agents.d/my-telegraf/values.yaml`:
442-
```yaml
443-
config_file: /custom/path/to/file
444-
backoff_delay: 30s
445-
```
446435

447-
5. Restart the agent control.
436+
```yaml
437+
config_file: /custom/path/to/file
438+
backoff_delay: 30s
439+
```
440+
441+
5. Restart Agent Control.

0 commit comments

Comments
 (0)