package tezt-tezos
Send and retrieve data points from InfluxDB.
Credentials used to authenticate to the database.
type config =
| V1_8 of {
url : Uri.t;
database : string;
credentials : credentials option;
measurement_prefix : string;
timeout : float;
}
InfluxDB configuration.
url
is the base URL of the InfluxDB API.
database
is the name of the InfluxDB database to read from and write to.
credentials
are used to authenticate to this database. If not provided, it will try to connect without authenticating (insecure mode).
measurement_prefix
is prepended to all measurement names when sending data points and in SELECT queries.
tags
is added to the tags of all data points when sending data points.
val config_of_json : Tezt_wrapper.JSON.t -> config
Read an InfluxDB configuration from a JSON value.
type data_point = private {
measurement : measurement;
first_field : field * field_value;
other_fields : (field * field_value) list;
timestamp : timestamp;
}
Data points (see function data_point
).
val data_point :
?tags:(tag * string) list ->
?other_fields:(field * field_value) list ->
?timestamp:timestamp ->
measurement ->
(field * field_value) ->
data_point
Create a data point.
Usage: data_point measurement key_value
Data points are composed of:
- a name
measurement
; - a possibly-empty list of
tags
to complete the name; - a non-empty list of
(key, value)
fields, composed ofkey_value
andother_fields
; - a UNIX
timestamp
(default value is now). See the documentation of InfluxDB for more information about those components.
val add_tag : tag -> string -> data_point -> data_point
Add a tag to a data point.
val show_data_point : data_point -> string
Convert a data point to a string for display purposes.
val write : config -> data_point list -> unit Lwt.t
Push data points to InfluxDB.
Return Error message
if the data could not be sent, where message
is a human-readable error message.
InfluxQL
This section provides a select
type that is an AST of InfluxQL SELECT queries, and a function to perform those queries.
See the documentation of InfluxQL here: https://docs.influxdata.com/influxdb/v1.8/query_language/explore-data
Time interval specifications for InfluxQL queries.
Grafana_interval
denotes $__interval
, a placeholder that Grafana replaces with an interval which is proportional to the selected time window size. Use this in a GROUP BY
clause. Example: ~group_by: (Time {interval = Grafana_interval; tag = None; fill = Some Previous})
. If you try to actually query
a select
with this, query
raises Invalid_arg
.
Functions for InfluxQL SELECT queries.
val column_name_of_func : func -> string
Get the name of the column for a given function in query results.
Columns to retrieve using InfluxQL SELECT queries.
type where =
| Tag of string * tag_operator * string
| Field of string * field_operator * field_value
| Or of where * where
| And of where * where
| Grafana_time_filter
WHERE clauses of InfluxQL SELECT queries.
Grafana_time_filter
denotes $timeFilter
, a placeholder that Grafana replaces with a predicate on time
which denotes the time window that the user selected in Grafana. If you try to actually query
a select
with this, query
raises Invalid_arg
.
type group_by =
| Tags of tag list
| Time of {
interval : time_interval;
tag : tag option;
fill : fill option;
}
GROUP BY clauses of InfluxQL SELECT queries.
type select = {
columns : column list;
from : from;
where : where option;
group_by : group_by option;
order_by : order_by option;
limit : int option;
slimit : int option;
}
InfluxQL SELECT queries.
FROM clauses of InfluxQL SELECT queries.
val select :
from:from ->
?where:where ->
?group_by:group_by ->
?order_by:order_by ->
?limit:int ->
?slimit:int ->
column list ->
select
Make an InfluxQL SELECT query.
val show_select : ?grafana:bool -> select -> string
Convert a SELECT query to a string for display purposes.
If grafana
is true
, allow Grafana_time_filter
and Grafana_interval
. Default is false
.
Prepend the measurement of the innermost SELECT query with the configured prefix.
This is automatically done by query
.
val show_result_data_point : result_data_point -> string
Convert a data point returned by a SELECT query to a human-readable string.
val query : config -> select -> result_data_point list list Lwt.t
Perform a SELECT query.
val get : string -> (Tezt_wrapper.JSON.t -> 'a) -> result_data_point -> 'a
Get a value from a data point in a query result.
Example: get "count" JSON.as_int
val show_query_result : result_data_point list list -> string
Convert results from a SELECT query into a string for debugging purposes.