Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

change: telegraf reqired tags added at internal code #182

Merged
merged 5 commits into from
Oct 20, 2023

Conversation

Ari-suhyeon
Copy link
Contributor

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • DevOps process (non-breaking change which improves efficiency and reliability for CI/CD)
  • Documentation only

What this PR does / why we need it:

Delete required tags from metric definition and handle them internally.

Which issue/s this PR fixes

fixes #180

How Has This Been Tested?

  • moon run tested - check telegraf.conf file
  • Unit Test has been tested.

Checklist:

@Ari-suhyeon Ari-suhyeon added this to the v0.0.15 milestone Oct 19, 2023
@Ari-suhyeon Ari-suhyeon requested a review from pueding October 19, 2023 07:30
@Ari-suhyeon Ari-suhyeon linked an issue Oct 19, 2023 that may be closed by this pull request
…nd telegraph metric definitions into toml strings
@@ -395,7 +397,64 @@ impl MetricCollectorManager {
};

let mut outputs_toml = toml::value::Array::new();
let mut inputs_map = HashMap::<String, Vec<serde_json::Map<std::string::String, serde_json::Value>>>::new();
if metric_definition.collector == "telegraf" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated code

metric_definition.collector == "telegraf"


let mut outputs_toml = toml::value::Array::new();
let mut inputs_map = HashMap::<String, Vec<serde_json::Map<std::string::String, serde_json::Value>>>::new();
if metric_definition.collector == "telegraf" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated line

error!("[telegraf] inputs not found");
continue;
};
let Some(inputs_object) = inputs.as_object() else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let Some(inputs_object) = metric_definition.metadata.get("inputs").and_then(|inputs| inputs.as_object()) else {
    error!("[telegraf] Failed to convert metadata.inputs to as_object");
    continue;
};

continue;
};

let mut inputs_object_arr = Vec::<serde_json::Map<std::string::String, serde_json::Value>>::new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment to describe the data structure

// 
// Example:
//  {                       // inputs_object
//      cloudwatch: [       // inputs_object_arr                  
//      {                   
//          cloudwatch
//       },
//      {
//          cloudwatch
//       }
// ]
//  }
// 
// 

let mut root_toml = "".to_string();
// Create a TOML array representing the metric definitions
for metric_definition in metric_definitions {
if !validation_vector_definition(metric_definition) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good that function names start with a verb

validation_vector_definition => validate_vector_definition

@pueding pueding merged commit c14a26a into main Oct 20, 2023
1 check passed
@pueding pueding deleted the 180-telegraf-delete-required-tags-and-handle-internal branch October 20, 2023 14:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

telegraf - delete required tags and handle internal
2 participants