Class: Infrawrench::BusinessMetricsNamespace

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

Overview

client.business_metrics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ BusinessMetricsNamespace

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

Parameters:



2368
2369
2370
2371
2372
# File 'lib/infrawrench/client.rb', line 2368

def initialize(transport)
  @transport = transport
  @get = BusinessMetricsGetNamespace.new(@transport)
  @values = BusinessMetricsValuesNamespace.new(@transport)
end

Instance Attribute Details

#getBusinessMetricsGetNamespace (readonly)

Returns client.business_metrics.get.

Returns:



2362
2363
2364
# File 'lib/infrawrench/client.rb', line 2362

def get
  @get
end

#valuesBusinessMetricsValuesNamespace (readonly)

Returns client.business_metrics.values.

Returns:



2364
2365
2366
# File 'lib/infrawrench/client.rb', line 2364

def values
  @values
end

Instance Method Details

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

Create a business metric

Keys must be unique per organization among live metrics — they are how workflows and the CLI address the metric. A key collision is a 409.

Requires permission: costs:write.

POST /api/org/orgId/business-metrics

Raises on 400: Bad request

Raises on 409: A live metric already uses this key.

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

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

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

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

Returns:

  • (Hash)

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

Raises:



2393
2394
2395
2396
2397
2398
2399
2400
2401
# File 'lib/infrawrench/client.rb', line 2393

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

#delete(id:, org_id: nil, request_options: nil) ⇒ Hash

Delete a business metric

Soft delete. Not refused when a dashboard card references the metric, unlike a saved cost filter: a unit-cost card whose metric is gone fails its query and says so, whereas a card that quietly reverted to plain spend would be a chart claiming to be something it is not.

Requires permission: costs:write.

DELETE /api/org/orgId/business-metrics/id

Raises on 404: Not found

Parameters:

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

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

  • id (String)

    Metric id or key

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

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

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

Returns:

  • (Hash)

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

Raises:



2422
2423
2424
2425
2426
2427
2428
2429
# File 'lib/infrawrench/client.rb', line 2422

def delete(id:, org_id: nil, request_options: nil)
  @transport.request(
    http_method: "DELETE",
    path: "/api/org/{orgId}/business-metrics/{id}",
    path_params: { "orgId" => org_id, "id" => id },
    request_options: request_options
  )
end

#unit_costs(id:, body:, org_id: nil, request_options: nil) ⇒ Hash

Query unit costs or margin

Divide spend by the metric, bucketed as asked. Three properties of the answer are worth knowing before reading it:

  • The ratio is computed at the requested bucket, from a summed numerator and a summed denominator — never a mean of daily ratios, which weights a quiet day as heavily as a peak one. The same holds for overallValue.
  • A missing or non-positive denominator is a gap (value: null with a gap reason), never 0 and never infinite.
  • Currencies are never merged. Spend in a currency with no stated rate keeps its own series rather than being dropped or added to another.

There is no groupBy: a per-group ratio would need a per-group denominator, and dividing each service's spend by the whole customer count produces numbers that do not sum to the real one.

Requires permission: costs:read.

POST /api/org/orgId/business-metrics/id/unit-costs

Raises on 400: Bad request

Raises on 404: Not found

Parameters:

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

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

  • id (String)

    Metric id or key

  • body (Hash)

    Request body, shaped as UnitCostQueryRequest.

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

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

  • id: (String)
  • body: (unit_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 UnitCostQueryResponse — see sig/infrawrench/sdk.rbs.

Raises:



2465
2466
2467
2468
2469
2470
2471
2472
2473
# File 'lib/infrawrench/client.rb', line 2465

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

#update(id:, body:, org_id: nil, request_options: nil) ⇒ Hash

Update a business metric

Replaces the whole definition. Changing key never orphans history — values are keyed on the metric's id — but it does break a workflow still writing to the old key, which is why the key is separate from the display name in the first place.

Requires permission: costs:write.

PUT /api/org/orgId/business-metrics/id

Raises on 400: Bad request

Raises on 404: Not found

Raises on 409: A live metric already uses this key.

Parameters:

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

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

  • id (String)

    Metric id or key

  • body (Hash)

    Request body, shaped as BusinessMetricInput.

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

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

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

Returns:

  • (Hash)

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

Raises:



2499
2500
2501
2502
2503
2504
2505
2506
2507
# File 'lib/infrawrench/client.rb', line 2499

def update(id:, body:, org_id: nil, request_options: nil)
  @transport.request(
    http_method: "PUT",
    path: "/api/org/{orgId}/business-metrics/{id}",
    path_params: { "orgId" => org_id, "id" => id },
    body: body,
    request_options: request_options
  )
end