Class: Infrawrench::QueryMonitorsNamespace

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

Overview

client.query_monitors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ QueryMonitorsNamespace

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

Parameters:



11971
11972
11973
11974
# File 'lib/infrawrench/client.rb', line 11971

def initialize(transport)
  @transport = transport
  @get = QueryMonitorsGetNamespace.new(@transport)
end

Instance Attribute Details

#getQueryMonitorsGetNamespace (readonly)

Returns client.query_monitors.get.

Returns:



11967
11968
11969
# File 'lib/infrawrench/client.rb', line 11967

def get
  @get
end

Instance Method Details

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

Create a query monitor

A monitor may only run select, with, show or explain, and only a single statement. That is a deliberate allowlist of leading keywords rather than a denylist of dangerous ones: a denylist has to be right about every dialect's spelling of every destructive verb, forever, and only has to be wrong once. Comments are stripped before the check, so -- harmless\nDROP TABLE x is rejected, and SELECT 1; DROP TABLE x is rejected by the single-statement rule.

Takes resources:execute, like the SQL editor: saving a monitor arranges for a query to run against a customer database on a schedule, forever, which is a strictly larger act than running one while watching it.

POST /api/org/orgId/query-monitors

Raises on 400: Bad request

Raises on 404: Not found

Raises on 409: Conflict

Parameters:

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

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

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

    Request body, shaped as QueryMonitorCreate.

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

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

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

Returns:

  • (Hash)

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

Raises:



12004
12005
12006
12007
12008
12009
12010
12011
12012
# File 'lib/infrawrench/client.rb', line 12004

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

#delete(monitor_id:, org_id: nil, request_options: nil) ⇒ nil

Delete a query monitor

DELETE /api/org/orgId/query-monitors/monitorId

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.

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

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

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

Returns:

  • (nil)

    This endpoint returns no content.

Raises:



12026
12027
12028
12029
12030
12031
12032
12033
12034
# File 'lib/infrawrench/client.rb', line 12026

def delete(monitor_id:, org_id: nil, request_options: nil)
  @transport.request(
    http_method: "DELETE",
    path: "/api/org/{orgId}/query-monitors/{monitorId}",
    path_params: { "orgId" => org_id, "monitorId" => monitor_id },
    accept: :empty,
    request_options: request_options
  )
end

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

List what a monitor can run against

The editor's target picker: each account with a SQL driver of its own, plus the SQL-capable resources inside it — a database that is a resource (a ClickHouse service, a D1 or Turso database, a Databricks SQL warehouse, a BigQuery dataset) rather than the account's own connection. Accounts with neither are omitted; a monitor pointed at one could only ever fail. Pass a resource's id (and optionally its resourceTypeId — the server fills it from the synced resource either way) when creating a monitor to scope the query to that resource.

GET /api/org/orgId/query-monitors/targets

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 QueryMonitorTargets — see sig/infrawrench/sdk.rbs.

Raises:



12055
12056
12057
12058
12059
12060
12061
12062
# File 'lib/infrawrench/client.rb', line 12055

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

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

Run a query once without saving it

The editor's 'try it' button. Goes through the same read-only guard as a scheduled run — a query that could not be saved as a monitor must not be runnable through the monitor's own preview — and applies the threshold, so the answer says whether it would be breaching rather than leaving the reader to compare two numbers.

POST /api/org/orgId/query-monitors/test

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, nil) (defaults to: nil)

    Request body, shaped as QueryMonitorCreate.

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

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

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

Returns:

  • (Hash)

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

Raises:



12083
12084
12085
12086
12087
12088
12089
12090
12091
# File 'lib/infrawrench/client.rb', line 12083

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

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

Edit a query monitor

Omitted fields are left alone and the result is validated after merging. Changing the query, the mode, the operator or the threshold re-arms the monitor: the stored breach streak was accumulated against a different question, and carrying it forward would fire an alert on the first run of a rule nobody has tested.

PATCH /api/org/orgId/query-monitors/monitorId

Raises on 400: Bad request

Raises on 404: Not found

Raises on 409: Conflict

Parameters:

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

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

  • monitor_id (String)
  • body (Hash, nil) (defaults to: nil)

    Request body, shaped as QueryMonitorUpdate.

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

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

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

Returns:

  • (Hash)

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

Raises:



12116
12117
12118
12119
12120
12121
12122
12123
12124
# File 'lib/infrawrench/client.rb', line 12116

def update(monitor_id:, org_id: nil, body: nil, request_options: nil)
  @transport.request(
    http_method: "PATCH",
    path: "/api/org/{orgId}/query-monitors/{monitorId}",
    path_params: { "orgId" => org_id, "monitorId" => monitor_id },
    body: body,
    request_options: request_options
  )
end