EDR File Lua Agent

Introduction

The EdrFileLuaAgent is an synchronous helper for Lua scripts running within the LogicApp. The EDR File Agent may be used by any Lua script, regardless of which Service initiated that script.

The EdrFileLuaAgent monitors EDR files directly on disk, looking for new and modified files. It reads the EDR text lines into an in-memory cache and provides an API for querying those EDRs based on key field values.

The EdrFileLuaAgent is uses specifically for regression testing of Event Data Records generated by applications.

NOTE: Althought the EdrFileLuaAgent module lives within the EdrApp directory, it does not communicate directly with the EdrApp at run-time.

EDR File Lua Agent methods are accessed via the “n2.n2svcd.edr_file_agent” module:

local edr_file_agent = require "n2.n2svcd.edr_file_agent"

Configuring EdrFileLuaAgent

The EdrFileLuaAgent is configured within a LogicApp.

<?xml version="1.0" encoding="utf-8"?>
<n2svcd>
  ...
  <applications>
    ...
    <application name="Logic" module="LogicApp">
      <include>
        <lib>../apps/logic/lib</lib>
      </include>
      <config>
        <services>
          ...
        </services>
        <agents>
          <agent module="EdrApp::EdrFileLuaAgent" libs="../apps/edr/lib">
              <config max_edrs_per_stream="2000" edr_margin_secs="3">
                  <streams>
                      <stream key="n2logic" directory="/tmp/edr"/>
                  </streams>
              </config>
          </agent>
        </agents>
      </config>
    </application>
    ...
  </application>
  ...
</n2svcd>

Under normal installation, the following agent attributes apply:

Parameter Name Type XML Type Description
module EdrApp::EdrFileLuaAgent Attribute [Required] The module name containing the Lua Agent code.
libs ../apps/db/lib Element Location of the module for EdrFileLuaAgent.
config Object Element Container for extended configuration for this Application instance.
.max_edrs_per_stream Integer Attribute The maximum number of EDRs to cache for each stream. Excess EDRs are discarded.
(Default = 1000)
.edr_check_ms Integer Attribute How often (in milliseconds) to check the EDR directory for new/modified EDR files and read new records.
(Default = 200)
.edr_margin_secs Integer Attribute A grace margin when filtering for EDRs with a time-stamp that is more recent than "start of call".
(Default = 2)
.edr_retire_secs Integer Attribute After the mtime for EDR file is this many seconds old, it is considered "retired" and the mtime will no longer be checked.
(Default = 300)
.streams Array Element Array of stream elements defining EDR file streams.

EDR File Streams

The EdrApp writes EDRs in “streams” of files which are written to a common directory and which have a common filename prefix.

The EDR File Agent reads one or more of these streams. It does not need to process all streams written by the EdrApp, only those which are of interest to test scripts.

Each stream Object in the config.streams Array is configured as follows.

Parameter Name Type XML Type Description
key String Attribute [Required] The stream key, matching the key from the EDR App Configuration.
directory String Attribute [Required] The full directory path where the EDR stream is being written, as configured in the EDR App Configuration or secondary directory after some post-processing.

The EdrFileLuaAgent API

All methods may raise a Lua Error in the case of exception, including:

Method Results

All methods return a single result with the following structure:

Parameter Type Description
result Table Container for the various returned parameters.
.instance_idx String The instance IDX for the instance whose EDR we matched.
e.g. 6c064234.
.upstream_idxs Table The instance IDXs for the instances upstream of the instance whose EDR we matched.
The first entry is the instance IDX associated with the originating instance.
.instance_gid String The instance GID for the instance whose EDR we matched.
e.g. [ scp01~Logic~1626138304~6c064234 ].
.upstream_gids Table The instance GIDs for the instances that are upstream of the instance whose EDR we matched.
The first entry is the instance GID associated with the originating instance.
.count Integer The number of EDRs returned.
.list List of Table A structure which holds all returned EDRs.
At the top level, this is a Lua table where the keys are the EDR event Types.
Within each event type table entry, the value is a list of all EDRs of that type.
Within that list each EDR is a table keyed by the EDR field names, plus header fields.

NOTE: The per-EDR tables in .list also include the following special field names which are parsed from the EDR header for each EDR.

.find_fields [Synchronous]

The find_fields method examines its cache of EDRs and begins by attempting to identify the first EDR:

Once that first EDR is identified, it return all EDRs: * From the EDR stream identified by stream_key. * Directly associated with the same instance as the first EDR.

An error is raised in the following cases:

The find_fields method takes the following parameters.

Parameter Type Description
stream_key String [Required] The key of the stream to search, as configured in the EdrFileLuaAgent and EdrApp.
match_event String [Required] The required event type for the primary correlating EDR.
match_fields Table [Required] A table containing one or more key/value pairs to exact-match in an EDR.

Example (EDR Matching):

local n2svcd = require "n2.n2svcd"
local edr_file_agent = require "n2.n2svcd.edr_file_agent"

local handler = function (rest_args)
    arg_EDR_FILE = edr_file_agent.find_fields ('n2scp', { CALLED = '4401234567' })
    n2svcd.match_kpath_size (arg_EDR_FILE, 'list.INITIALDP', 1, true)
    n2svcd.match_kpath_string (arg_EDR_FILE, 'list.INITIALDP.[0].CALLING', '09773322')
    n2svcd.match_kpath_string (arg_EDR_FILE, 'list.INITIALDP.[0].TRIGGER', 'ORIG')
end

return n2svcd.handler (handler)

.find_gid [Synchronous]

The find_gid method examines its cache of EDRs and returns all EDRs:

The find_gid method takes the following parameters.

Parameter Type Description
stream_key String [Required] The key of the stream to search, as configured in the EdrFileLuaAgent and EdrApp.
instance_gid String [Required] The required instance GID that identifies the instance whose EDRs should be returned.

Example (EDR Matching):

local n2svcd = require "n2.n2svcd"
local edr_file_agent = require "n2.n2svcd.edr_file_agent"

local handler = function (rest_args)
    arg_EDR_FILE = edr_file_agent.find_gid ('n2scp', 'scp01~LHO SCP~1626138304~6c064234')
    n2svcd.match_kpath_size (arg_EDR_FILE, 'list.INITIAL_DP', 1, true)
    n2svcd.match_kpath_string (arg_EDR_FILE, 'list.INITIALDP.[0].CALLING', '09773322')
    n2svcd.match_kpath_string (arg_EDR_FILE, 'list.INITIALDP.[0].TRIGGER', 'ORIG')
end

return n2svcd.handler (handler)

.find_upstream_gid [Synchronous]

The find_upstream_gid method examines its cache of EDRs and begins by attempting to identify the first EDR:

Once that first EDR is identified, it return all EDRs: * From the EDR stream identified by stream_key. * Directly associated with the same instance as the first EDR.

An error is raised in the following cases:

The find_upstream_gid method takes the following parameters.

Parameter Type Description
stream_key String [Required] The key of the stream to search, as configured in the EdrFileLuaAgent and EdrApp.
instance_gid String [Required] The instance GID that identifies a required preceding instance for the target EDRs.
app_name String [Required] The name of the application that is required to be associated with the instance for the primary correlating EDR.

Example (EDR Matching):

local n2svcd = require "n2.n2svcd"
local edr_file_agent = require "n2.n2svcd.edr_file_agent"

local handler = function (rest_args)
    arg_EDR_FILE = edr_file_agent.find_upstream_gid ('n2scp', 'scp01~LHO SCP~1626138304~6c064234', 'Logic')
    n2svcd.match_kpath_size (arg_EDR_FILE, 'list.LOGIC', 1, true)
    n2svcd.match_kpath_string (arg_EDR_FILE, 'list.LOGIC.[0].CUSTOM', 'Custom 1')
end

return n2svcd.handler (handler)