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:



1841
1842
1843
1844
# File 'lib/infrawrench/client.rb', line 1841

def initialize(transport)
  @transport = transport
  @anomaly_settings = CostsAnomalySettingsNamespace.new(@transport)
end

Instance Attribute Details

#anomaly_settingsCostsAnomalySettingsNamespace (readonly)

Returns client.costs.anomaly_settings.

Returns:



1837
1838
1839
# File 'lib/infrawrench/client.rb', line 1837

def anomaly_settings
  @anomaly_settings
end

Instance Method Details

#anomalies(org_id: nil, days: nil, request_options: nil) ⇒ Hash

List recently detected cost anomalies

Spend anomalies detected by the daily background pass. Two kinds share the list: a spike, where a provider's or service's spend exceeded its trailing 28-day baseline by a statistical threshold (mean + N·stddev, with an absolute floor to ignore penny-scale noise), and a new_source, where a provider or service with no spend at all across that window suddenly billed a material amount. Thresholds are per organization — see GET /costs/anomaly-settings. Newest day first, capped at 200 rows.

Requires permission: costs:read.

GET /api/org/orgId/costs/anomalies

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.

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

    Window in days over anomalous days, 1-90. Defaults to 30.

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

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

  • org_id: (String, nil) (defaults to: nil)
  • days: (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:



1868
1869
1870
1871
1872
1873
1874
1875
1876
# File 'lib/infrawrench/client.rb', line 1868

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

#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.

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", "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:



1897
1898
1899
1900
1901
1902
1903
1904
1905
# File 'lib/infrawrench/client.rb', line 1897

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

#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.

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:



1926
1927
1928
1929
1930
1931
1932
1933
1934
# File 'lib/infrawrench/client.rb', line 1926

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:



1964
1965
1966
1967
1968
1969
1970
1971
1972
# File 'lib/infrawrench/client.rb', line 1964

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, 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.

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.

  • 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)
  • request_options: (Hash[Symbol, untyped], nil) (defaults to: nil)

Returns:

  • (Hash)

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

Raises:



1993
1994
1995
1996
1997
1998
1999
2000
2001
# File 'lib/infrawrench/client.rb', line 1993

def showback(org_id: nil, from: nil, to: 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 },
    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:



2017
2018
2019
2020
2021
2022
2023
2024
# File 'lib/infrawrench/client.rb', line 2017

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, 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.

  • 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)
  • request_options: (Hash[Symbol, untyped], nil) (defaults to: nil)

Returns:

  • (Hash)

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

Raises:



2047
2048
2049
2050
2051
2052
2053
2054
2055
# File 'lib/infrawrench/client.rb', line 2047

def untagged(org_id: nil, from: nil, to: 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 },
    request_options: request_options
  )
end