Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tag-filtering): enable tag filtering metrics #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pavelsidla
Copy link

Enabling tag based filtering metrics

@pavelsidla
Copy link
Author

Hello
I am trying to enable tag based filtering metrics.
It can be used but i make it to not be mandatory, please review my code and lets discuss this option.
Thank you

@gluckzhang
Copy link
Member

Hi @pavelsidla, thank you for this nice PR! I think it is indeed helpful. Maybe later we can make it more generic and work for other kinds of filters (e.g., Dimensions). For this PR, I think it is good to just work on tag filters.

My key suggestion is to make the configuration like the following, what do you think?

metrics:
  tag_filters:
    - tag_key: 'my_org:team' # because it is possible to have such tags in AWS, we may need this config format to support them
      tag_values:
        - dev-team-1
        - dev-team-2
    - tag_key: EnvironmentName
      tag_values:
        - dev

@pavelsidla
Copy link
Author

Hello i made change in code to allign it with your requirements. Please check if its ok :)

Copy link
Member

@gluckzhang gluckzhang left a comment

Choose a reason for hiding this comment

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

Hi @pavelsidla, thanks for the updates! There are some minor issues regarding the validation and a for loop. Please check my comments. I think the PR is good to be merged after fixing them :)

# Include tag filters if provided
if tag_filters:
tag_filter_list = []
for tag_filter in tag_filters:
Copy link
Member

Choose a reason for hiding this comment

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

I believe this for loop should be put under the if block, right?

@@ -26,6 +26,11 @@ metrics:
tag_value: other
# Allowed values for metric type are AmortizedCost, BlendedCost, NetAmortizedCost, NetUnblendedCost, NormalizedUsageAmount, UnblendedCost, and UsageQuantity
metric_type: AmortizedCost
tag_filters:
Copy link
Member

Choose a reason for hiding this comment

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

Could you also update this config example? Thanks :)

@@ -46,6 +51,11 @@ metrics:
tag_value: other
# Allowed values for metric type are AmortizedCost, BlendedCost, NetAmortizedCost, NetUnblendedCost, NormalizedUsageAmount, UnblendedCost, and UsageQuantity
metric_type: AmortizedCost
tag_filters:
Copy link
Member

Choose a reason for hiding this comment

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

Same here, needs to be updated.

# Validate tag_filters if present
if "tag_filters" in config_metric:
tag_filters = config_metric["tag_filters"]
if not isinstance(tag_filters, dict):
Copy link
Member

Choose a reason for hiding this comment

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

This check should be if not isinstance(tag_filters, list) now.

for group in config_metric["group_by"]["groups"]:
if group["label_name"] in group_label_names:
logging.error("Group label names should be unique!")
for tag_key, tag_values in tag_filters.items():
Copy link
Member

Choose a reason for hiding this comment

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

Please update this validation as well.

@pavelsidla
Copy link
Author

Hello i am sorry for mistakes ill fix them tomorrow, and thank you for make that suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants