Class: Infrawrench::CostsNamespace

Inherits:
Object
  • Object
show all
Defined in:
lib/infrawrench/client.rb,
sig/infrawrench/sdk.rbs

Overview

client.costs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ CostsNamespace

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CostsNamespace.

Parameters:



5077
5078
5079
5080
5081
5082
# File 'lib/infrawrench/client.rb', line 5077

def initialize(transport)
  @transport = transport
  @anomalies = CostsAnomaliesNamespace.new(@transport)
  @anomaly_settings = CostsAnomalySettingsNamespace.new(@transport)
  @efficiency_alert_settings = CostsEfficiencyAlertSettingsNamespace.new(@transport)
end

Instance Attribute Details

#anomaliesCostsAnomaliesNamespace (readonly)

Returns client.costs.anomalies.

Returns:



5069
5070
5071
# File 'lib/infrawrench/client.rb', line 5069

def anomalies
  @anomalies
end

#anomaly_settingsCostsAnomalySettingsNamespace (readonly)

Returns client.costs.anomaly_settings.

Returns:



5071
5072
5073
# File 'lib/infrawrench/client.rb', line 5071

def anomaly_settings
  @anomaly_settings
end

#efficiency_alert_settingsCostsEfficiencyAlertSettingsNamespace (readonly)

Returns client.costs.efficiency_alert_settings.

Returns:



5073
5074
5075
# File 'lib/infrawrench/client.rb', line 5073

def efficiency_alert_settings
  @efficiency_alert_settings
end

Instance Method Details

#dimensions(dimension:, org_id: nil, tag_key: nil, request_options: nil) ⇒ Hash

List distinct values for a cost dimension

Feeds the filter and group-by pickers. Pass dimension=tag-keys for tag keys; dimension=tag requires tagKey. charge_type answers from the fixed set of charge types rather than from the stored data, so the picker is populated before any provider has reported one.

Requires permission: costs:read.

GET /api/org/orgId/costs/dimensions

Raises on 400: Bad request

Parameters:

  • org_id (String, nil) (defaults to: nil)

    Organization id. Defaults to the org_id the client was constructed with.

  • dimension (String)
  • tag_key (String, nil) (defaults to: nil)
  • request_options (Hash, nil) (defaults to: nil)

    Per-call :headers, :timeout and :open_timeout.

  • dimension: ("provider", "account", "service", "region", "resource", "tag", "charge_type", "commitment", "tag-keys")
  • org_id: (String, nil) (defaults to: nil)
  • tag_key: (String, nil) (defaults to: nil)
  • request_options: (Hash[Symbol, untyped], nil) (defaults to: nil)

Returns:

  • (Hash)

    Parsed JSON, shaped as CostDimensionValues — see sig/infrawrench/sdk.rbs.

Raises:



5105
5106
5107
5108
5109
5110
5111
5112
5113
# File 'lib/infrawrench/client.rb', line 5105

def dimensions(dimension:, org_id: nil, tag_key: nil, request_options: nil)
  @transport.request(
    http_method: "GET",
    path: "/api/org/{orgId}/costs/dimensions",
    path_params: { "orgId" => org_id },
    query: { "dimension" => dimension, "tagKey" => tag_key },
    request_options: request_options
  )
end

#efficiency_alerts(org_id: nil, kind: nil, limit: nil, request_options: nil) ⇒ Hash

Recently fired efficiency alerts

The three slow-lane cost alerts in one feed, newest first: commitments about to lapse, commitments that are not being used, and business metrics whose cost per unit rose. Unlike budgets, anomalies and change alerts — all of which compare a spend total against another spend total — these read the commitment calendar and the volume the spend bought, so they see the two surprises the other three structurally cannot.

Requires permission: costs:read.

GET /api/org/orgId/costs/efficiency-alerts

Raises on 400: Bad request

Parameters:

  • org_id (String, nil) (defaults to: nil)

    Organization id. Defaults to the org_id the client was constructed with.

  • kind (String, nil) (defaults to: nil)

    Restrict to one detector. Omitted returns all three, interleaved by time.

  • limit (Integer, nil) (defaults to: nil)

    Rows to return, newest first. Defaults to 50.

  • request_options (Hash, nil) (defaults to: nil)

    Per-call :headers, :timeout and :open_timeout.

  • org_id: (String, nil) (defaults to: nil)
  • kind: ("commitment_expiry", "commitment_idle", "unit_cost_regression", nil) (defaults to: nil)
  • limit: (Integer, nil) (defaults to: nil)
  • request_options: (Hash[Symbol, untyped], nil) (defaults to: nil)

Returns:

  • (Hash)

    Parsed JSON, shaped as Hash — see sig/infrawrench/sdk.rbs.

Raises:



5138
5139
5140
5141
5142
5143
5144
5145
5146
# File 'lib/infrawrench/client.rb', line 5138

def efficiency_alerts(org_id: nil, kind: nil, limit: nil, request_options: nil)
  @transport.request(
    http_method: "GET",
    path: "/api/org/{orgId}/costs/efficiency-alerts",
    path_params: { "orgId" => org_id },
    query: { "kind" => kind, "limit" => limit },
    request_options: request_options
  )
end

#query(body:, org_id: nil, request_options: nil) ⇒ Hash

Query aggregated cost series

Aggregates collected provider spend into per-bucket, per-group series for cost graphs. Currencies are never merged; mixed-currency orgs get one series per currency. Optionally returns a previous-period comparison and a trend forecast.

costBasis chooses between cash and amortized money, and chargeTypes narrows which kinds of charge count. Both the comparison period and the forecast are computed on the same basis and charge types as the series itself.

The filter can be sent structurally as filters or as text in the cost query language via query (provider = 'aws' AND tag['env'] != 'dev'). They are two spellings of one filter: sending both is a 400, and a query that does not parse is a 400 carrying the offset of the mistake.

Requires permission: costs:read.

POST /api/org/orgId/costs/query

Raises on 400: Bad request

Parameters:

  • org_id (String, nil) (defaults to: nil)

    Organization id. Defaults to the org_id the client was constructed with.

  • body (Hash)

    Request body, shaped as CostQueryRequest.

  • request_options (Hash, nil) (defaults to: nil)

    Per-call :headers, :timeout and :open_timeout.

  • body: (cost_query_request)
  • org_id: (String, nil) (defaults to: nil)
  • request_options: (Hash[Symbol, untyped], nil) (defaults to: nil)

Returns:

  • (Hash)

    Parsed JSON, shaped as CostQueryResponse — see sig/infrawrench/sdk.rbs.

Raises:



5177
5178
5179
5180
5181
5182
5183
5184
5185
# File 'lib/infrawrench/client.rb', line 5177

def query(body:, org_id: nil, request_options: nil)
  @transport.request(
    http_method: "POST",
    path: "/api/org/{orgId}/costs/query",
    path_params: { "orgId" => org_id },
    body: body,
    request_options: request_options
  )
end

#rows(body:, org_id: nil, request_options: nil) ⇒ Hash

Push cost rows from your own systems

Reports spend Infrawrench has no provider plugin for — a parsed SaaS invoice, an internal chargeback, a colo bill — into the same store the provider collectors write to, so it appears in cost graphs, dimension filters, and budgets alongside everything else.

Rows are grouped under a caller-chosen source. Writes are idempotent per (source, day, service, region, resourceId, tags, currency): pushing the same day again restates that day rather than adding to it, so a nightly job can safely re-push a trailing window. Rows pushed under a source can never overwrite rows a provider collector wrote.

The whole batch is validated before anything is stored, so a 400 means nothing was written.

Requires permission: costs:write.

POST /api/org/orgId/costs/rows

Raises on 400: Bad request

Parameters:

  • org_id (String, nil) (defaults to: nil)

    Organization id. Defaults to the org_id the client was constructed with.

  • body (Hash)

    Request body, shaped as CostPushRequest.

  • request_options (Hash, nil) (defaults to: nil)

    Per-call :headers, :timeout and :open_timeout.

  • body: (cost_push_request)
  • org_id: (String, nil) (defaults to: nil)
  • request_options: (Hash[Symbol, untyped], nil) (defaults to: nil)

Returns:

  • (Hash)

    Parsed JSON, shaped as CostPushResponse — see sig/infrawrench/sdk.rbs.

Raises:



5215
5216
5217
5218
5219
5220
5221
5222
5223
# File 'lib/infrawrench/client.rb', line 5215

def rows(body:, org_id: nil, request_options: nil)
  @transport.request(
    http_method: "POST",
    path: "/api/org/{orgId}/costs/rows",
    path_params: { "orgId" => org_id },
    body: body,
    request_options: request_options
  )
end

#showback(org_id: nil, from: nil, to: nil, basis: nil, adjusted: nil, request_options: nil) ⇒ Hash

Spend grouped by cost centre (showback)

Runs the org's allocation rules over collected spend and sums per cost centre and currency. Spend no rule claims comes back as the "Unallocated" bucket; every defined centre appears even with zero spend.

Cost centres nest, so the list is a depth-first tree. Each entry carries totals (spend allocated directly to it) and subtreeTotals (its own plus every descendant's) — "Engineering, of which Platform" needs both. Rules still evaluate first-match-wins by ascending priority against a flat list, so a row is allocated exactly once even when a rule targets a parent and another targets its child; at equal priority the more deeply nested centre wins.

Requires permission: costs:read.

GET /api/org/orgId/costs/showback

Raises on 400: Bad request

Parameters:

  • org_id (String, nil) (defaults to: nil)

    Organization id. Defaults to the org_id the client was constructed with.

  • from (String, nil) (defaults to: nil)

    Defaults to 30 days ago.

  • to (String, nil) (defaults to: nil)

    Defaults to today.

  • basis (String, nil) (defaults to: nil)

    Which money to sum. cash (the default) is what the provider charged on the day it charged it; amortized spreads a commitment's up-front fee across the term it buys. Providers that report no amortized amount fall back to their cash amount.

  • adjusted (String, nil) (defaults to: nil)

    Apply the organization's billing rules (see /billing-rules): markups multiply, and a reallocation moves a centre's spend onto another centre. Off by default — a chargeback report that silently showed marked-up numbers is one the receiving team could not reconcile. On, the response carries adjustment with the collected totals beside the adjusted ones. Fixed-amount rules are booked onto the cost centre they name (or "Unallocated" when they name none), pro-rated across the period.

  • request_options (Hash, nil) (defaults to: nil)

    Per-call :headers, :timeout and :open_timeout.

  • org_id: (String, nil) (defaults to: nil)
  • from: (String, nil) (defaults to: nil)
  • to: (String, nil) (defaults to: nil)
  • basis: ("cash", "amortized", nil) (defaults to: nil)
  • adjusted: ("true", "false", nil) (defaults to: nil)
  • request_options: (Hash[Symbol, untyped], nil) (defaults to: nil)

Returns:

  • (Hash)

    Parsed JSON, shaped as ShowbackReport — see sig/infrawrench/sdk.rbs.

Raises:



5262
5263
5264
5265
5266
5267
5268
5269
5270
# File 'lib/infrawrench/client.rb', line 5262

def showback(org_id: nil, from: nil, to: nil, basis: nil, adjusted: nil, request_options: nil)
  @transport.request(
    http_method: "GET",
    path: "/api/org/{orgId}/costs/showback",
    path_params: { "orgId" => org_id },
    query: { "from" => from, "to" => to, "basis" => basis, "adjusted" => adjusted },
    request_options: request_options
  )
end

#status(org_id: nil, request_options: nil) ⇒ Hash

Per-account cost collection status

Which accounts support cost collection, whether their history backfill has completed, and the ingested date coverage.

Requires permission: costs:read.

GET /api/org/orgId/costs/status

Parameters:

  • org_id (String, nil) (defaults to: nil)

    Organization id. Defaults to the org_id the client was constructed with.

  • request_options (Hash, nil) (defaults to: nil)

    Per-call :headers, :timeout and :open_timeout.

  • org_id: (String, nil) (defaults to: nil)
  • request_options: (Hash[Symbol, untyped], nil) (defaults to: nil)

Returns:

  • (Hash)

    Parsed JSON, shaped as Hash — see sig/infrawrench/sdk.rbs.

Raises:



5286
5287
5288
5289
5290
5291
5292
5293
# File 'lib/infrawrench/client.rb', line 5286

def status(org_id: nil, request_options: nil)
  @transport.request(
    http_method: "GET",
    path: "/api/org/{orgId}/costs/status",
    path_params: { "orgId" => org_id },
    request_options: request_options
  )
end

#untagged(org_id: nil, from: nil, to: nil, basis: nil, request_options: nil) ⇒ Hash

Untagged spend over the required tag keys

Spend on cost rows missing at least one of the org's required tag keys, overall and per key, plus the largest untagged (account, service) buckets. Empty when no tag policy is configured — untagged is only meaningful against a policy.

Requires permission: costs:read.

GET /api/org/orgId/costs/untagged

Raises on 400: Bad request

Parameters:

  • org_id (String, nil) (defaults to: nil)

    Organization id. Defaults to the org_id the client was constructed with.

  • from (String, nil) (defaults to: nil)

    Defaults to 30 days ago.

  • to (String, nil) (defaults to: nil)

    Defaults to today.

  • basis (String, nil) (defaults to: nil)

    Which money to sum. cash (the default) is what the provider charged on the day it charged it; amortized spreads a commitment's up-front fee across the term it buys. Providers that report no amortized amount fall back to their cash amount.

  • request_options (Hash, nil) (defaults to: nil)

    Per-call :headers, :timeout and :open_timeout.

  • org_id: (String, nil) (defaults to: nil)
  • from: (String, nil) (defaults to: nil)
  • to: (String, nil) (defaults to: nil)
  • basis: ("cash", "amortized", nil) (defaults to: nil)
  • request_options: (Hash[Symbol, untyped], nil) (defaults to: nil)

Returns:

  • (Hash)

    Parsed JSON, shaped as UntaggedSpendReport — see sig/infrawrench/sdk.rbs.

Raises:



5320
5321
5322
5323
5324
5325
5326
5327
5328
# File 'lib/infrawrench/client.rb', line 5320

def untagged(org_id: nil, from: nil, to: nil, basis: nil, request_options: nil)
  @transport.request(
    http_method: "GET",
    path: "/api/org/{orgId}/costs/untagged",
    path_params: { "orgId" => org_id },
    query: { "from" => from, "to" => to, "basis" => basis },
    request_options: request_options
  )
end