smart_city_data v3.0.2 SmartCity.Data.Timing View Source

Timing struct for adding timing metrics to SmartCity.Data messages

Link to this section Summary

Functions

Gets the current time. This function should always be used for generating times to be used in timings to ensure consistency across all services.

Wraps the results of a function call with measured timing information

Creates a new SmartCity.Data.Timing from opts.

Creates a new SmartCity.Data.Timing struct, passing in all fields.

Validate that all required keys are present and valid (not nil).

Validate that all required keys are present and valid (not nil).

Link to this section Types

Link to this type

t()

View Source
t() :: %SmartCity.Data.Timing{
  app: String.t(),
  end_time: DateTime.t(),
  label: String.t(),
  start_time: DateTime.t()
}

Link to this section Functions

Link to this function

current_time()

View Source
current_time() :: String.t()

Gets the current time. This function should always be used for generating times to be used in timings to ensure consistency across all services.

Returns current UTC Time in ISO8601 format

Link to this function

measure(app, label, function)

View Source
measure(String.t(), String.t(), (() -> {:ok, term()} | {:error, term()})) ::
  {:ok, term(), SmartCity.Data.Timing.t()} | {:error, String.t()}

Wraps the results of a function call with measured timing information

Returns {:ok, result, timing} on success, or {:error, reason} on failure

Link to this function

new(opts)

View Source
new(
  %{
    :app => term(),
    :label => term(),
    optional(:start_time) => term(),
    optional(:end_time) => term()
  }
  | list()
) :: SmartCity.Data.Timing.t()

Creates a new SmartCity.Data.Timing from opts.

Returns a SmartCity.Data.Timing struct or raises ArgumentError

Parameters

  • opts: Keyword list or map containing struct attributes

    Required keys: `app`, `label`
    See [`Kernel.struct!/2`](https://hexdocs.pm/elixir/Kernel.html#struct!/2).
Link to this function

new(app, label, start_time, end_time)

View Source
new(term(), term(), term(), term()) :: SmartCity.Data.Timing.t()

Creates a new SmartCity.Data.Timing struct, passing in all fields.

Returns a SmartCity.Data.Timing struct or raises ArgumentError.

Parameters

  • app: application for which timing metrics are being measured
  • label: description of timing measurement
  • start_time: time when measurement has begun
  • end_time: time when measurement has finished

Examples

iex> SmartCity.Data.Timing.new("foo", "bar", "not_validated", "not_validated")
%SmartCity.Data.Timing{
  app: "foo",
  label: "bar",
  start_time: "not_validated",
  end_time: "not_validated"
}

Validate that all required keys are present and valid (not nil).

Set by @validate_keys module attribute. Currently checks: app, label

Returns {:ok, timing} on success or {:error, reason} on failure

Parameters

Validate that all required keys are present and valid (not nil).

Returns timing on success, or raises ArgumentError on failure See validate/1