Skip to content

ARCH-10: monthlyCostFromConvertibleRI money formula duplicated verbatim, with bare 730/8760 despite named constants [go part] #109

Open

Description

@cristim

Split from LeanerCloud/cloud-commitments-cli#1199 (cross-component issue, monorepo split)

Severity: P3. Confidence: high. Informational.

Affected files:

  • providers/aws/recommendations/parser_sp.go:241-242 (defines const hoursPerMonth = 730.0, the canonical constant)

Recommendation:
Move the shared money-display formula next to ec2svc.ConvertibleRI or into a shared exchange package with a shared HoursPerMonth constant, so callers in other repos (e.g. cloud-commitments-platform's internal/api/handler_ri_exchange.go and internal/server/handler_ri_exchange.go, which currently hardcode a bare 730) can reuse it instead of re-deriving it.

Findings from the 2026-09-02 codebase audit (A08b-044)

The same bare-constant problem has a wider footprint than the monthlyCostFromConvertibleRI duplication. 8760.0 appears as an inline literal on money paths in twelve provider files:

  • Azure: providers/azure/services/cache/client.go:548, cosmosdb/client.go:548, database/client.go:567, search/client.go:463, managedredis/client.go:492, synapse/client.go:439, compute/client.go:709, savingsplans/client.go:411
  • GCP: providers/gcp/services/cloudsql/client.go:363, cloudstorage/client.go:356, memorystore/client.go:350, computeengine/client.go:822

As with 730, a named constant is the fix, in the shared pricing helper both providers already import.

A second, adjacent hygiene item in the same files: the GCP billing service IDs are opaque and uncommented, e.g. services/9662-B51E-5089 at providers/gcp/services/cloudsql/client.go:350 plus the equivalents at cloudstorage/client.go:343 (services/95FF-2EF5-5EA1), memorystore/client.go:337 (services/D559-82DA-3A56) and computeengine/client.go:809 (services/6F81-5844-456A). A transposed digit there yields an empty SKU catalog that surfaces as "no pricing found" rather than an error, so naming each as a documented package constant is worth doing in the same pass.

Re-verified live on 2026-09-27: hoursPerMonth still at parser_sp.go:241-242; all twelve 8760.0 sites and all four GCP ListSKUs("services/...") literals confirmed present at the line numbers above (drifted slightly from the original audit's numbers due to unrelated commits, but all still exist as bare literals).

Acceptance criteria

  • hoursPerMonth/HoursPerMonth (or equivalent) is exported from a location importable by both AWS, Azure and GCP provider packages (and, ideally, by cloud-commitments-platform's exchange handlers, which currently duplicate the formula with a bare 730).
  • All twelve 8760.0 literals in the Azure and GCP client files listed above are replaced with the shared constant (or a locally-named hoursPerYear/equivalent that documents its relationship to hoursPerMonth).
  • The four opaque GCP billing service IDs (9662-B51E-5089, 95FF-2EF5-5EA1, D559-82DA-3A56, 6F81-5844-456A) become named, documented package constants instead of inline string literals.
  • No behavior change; this is a magic-value/duplication cleanup only.

Activity

  1. cristim commented on Oct 17, 2026

    @cristim
    MemberAuthor

    Checked against main: the monthlyCostFromConvertibleRI half is platform-side. The 8760 literals sit in 12 Azure and GCP client files, which open PRs #473, #424, #433, #471, #493 and #307 edit. Blocked on those PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions