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

CP 19442: CloudAccountId must be a string #53

Merged
merged 4 commits into from
Jul 11, 2024

Conversation

JonParsons11350
Copy link
Contributor

@JonParsons11350 JonParsons11350 commented Jul 10, 2024

By submitting a PR to this repository, you agree to the terms within the CloudZero Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.

Description

Problem

The issue is with cloudAccountId being a large integer. What happens is, before the cloudAccountId reaches our helm chart, it has changed into scientific notation.

Among others, you can see people discussing the issue here: helm/helm#1707

If cloudAccountId is being passed as an explicit argument, eg. --set cloudAccountId=123123123123123123123123123123
it works as expected

But when using -f to include a file that has the cloudAccountId, it gets converted to scientific notation.

Alternatives considered

Tried a few approaches that were non ideal.

  1. In helm chart, cast the value to an integer (which works for scientific notation), and then use that value if it's a number > 0, otherwise assume it was a string. See the first commit on this branch for that attempt.
    This does not work if either a) the conversion to scientific notation lost precision, eg. 123123123123123123 ends up as like 123123123123123000 . or b) leading zero's are significant, which apparently they are in AWS.

  2. Helm hooks - can't rely on these since customers are likely using tools like argo or spinaker rather than helm

Solution

We must mandate that cloudAccountId is a string. This prevents the issue, and gives the user immediate feedback about the issue.
It might be annoying for customers, but it also feels justifiable. Consider this description from CoPilot (emphasis mine):

AWS Account ID: This is typically a 12-digit integer, but when used in configurations, SDKs, or when specified in policies, it's treated as a string because leading zeros are significant.

GCP Project Number: This is an integer. However, like AWS Account IDs, when used programmatically or in configurations, it's often treated as a string to maintain consistency across various systems that might require string input.

Azure Subscription ID: This is a GUID (Globally Unique Identifier), which is not an integer. GUIDs are alphanumeric strings (including hyphens) that follow a specific structure, such as 12345678-1234-1234-1234-123456789abc. Therefore, Azure Subscription IDs are always treated as strings.

Testing

Running command like this:
helm template cz-prom-agent . --set apiKey=$api_key --set clusterName=jonp --set host=dev-api.cloudzero.com --set createSecret=true --set prometheus-node-exporter.enabled=true --set kube-state-metrics.enabled=true --set clusterName='jonp-test-cluster' -f extra-values.yaml | grep remote_write -A 2
with cloudAccountId set to integer gives this immediate feedback:

cloudzero-agent:
- cloudAccountId: Invalid type. Expected: string, given: integer
  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not main

@dmepham
Copy link
Collaborator

dmepham commented Jul 10, 2024

@JonParsons11350

Mandate that cloudAccountId is a string - this prevents the issue, and gives the user immediate feedback about the issue.

I think this is a good solution given the drawbacks of trying to handle it within the chart

@JonParsons11350 JonParsons11350 force-pushed the cp-19442-account-id-as-string-2 branch from 967b101 to b6cf907 Compare July 11, 2024 14:00
@JonParsons11350 JonParsons11350 changed the title CP 19442: Semi-working attempt, cast to int then back to string CP 19442: CloudAccountId must be a string Jul 11, 2024
@JonParsons11350 JonParsons11350 marked this pull request as ready for review July 11, 2024 14:29
@JonParsons11350 JonParsons11350 requested a review from a team as a code owner July 11, 2024 14:29
Copy link
Contributor

@roberthocking roberthocking left a comment

Choose a reason for hiding this comment

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

Looks Good :shipit:

@josephbarnett
Copy link
Contributor

Nice, Great write up!

Copy link
Collaborator

@dmepham dmepham left a comment

Choose a reason for hiding this comment

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

just a changelog request, looks great!

@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.12]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do think we're on 0.0.13 technically, we may just be missing the notes from .12. I think the eventual goal plan is to have github actions update this, but for now, would you mind bumping this to 0.13 and adding the release notes for .12 here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

@@ -157,7 +157,7 @@ data:
{{- end}}
{{- end}}
remote_write:
- url: 'https://{{ .Values.host }}/v1/container-metrics?cluster_name={{.Values.clusterName}}&cloud_account_id={{.Values.cloudAccountId | toString}}&region={{.Values.region}}'
- url: 'https://{{ .Values.host }}/v1/container-metrics?cluster_name={{.Values.clusterName | urlquery}}&cloud_account_id={{.Values.cloudAccountId | urlquery}}&region={{.Values.region | urlquery}}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh nice, I didn't know about that function

@JonParsons11350 JonParsons11350 merged commit 6eb776b into develop Jul 11, 2024
2 checks passed
@JonParsons11350 JonParsons11350 deleted the cp-19442-account-id-as-string-2 branch July 11, 2024 15:41
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.

4 participants