Contents

Data Store Overview

Data Store microservice supports Video and Time series use cases. ### Data Store Microservice The Data Store microservice supports two type of Data: - Metadata (JSON)(InfluxDB) - Blob (MinIO Object Storage)

Steps to Independently Build and Deploy Data Store Microservice

Note: For running two or more microservices, you are recommended to try the use case-driven approach for building and deploying as described at Generate Consolidated Files for a Subset of Edge Insights for Industrial Services

Steps to Independently Build the Data Store Microservice

Note: When switching between independent deployment of the service with and without config manager agent service dependency, one would run into issues with docker compose build w.r.t Certificates folder existence. As a workaround, run the command sudo rm -rf Certificates to proceed with the docker compose build.

To independently build the Data Store microservice, complete the following steps:

  1. The downloaded source code should have a directory named Data Store:

    If cloned using Manifest File,

    # Enter the Data Store directory
    cd IEdgeInsights/DataStore
    

    If cloned Data Store repo directly

    # Enter the Data Store directory
    cd applications.industrial.edge-insights.data-store
    
  2. Independently build

    docker compose build
    

Steps to Independently Deploy Data Store Microservice

You can deploy the Data Store service in either of the following two ways:: - Deploy Data Store Service without Config Manager Agent Dependency - Deploy Data Store Service with Config Manager Agent Dependency

Deploy Data Store Service without Config Manager Agent Dependency

Run the following commands to deploy Data Store service without Config Manager Agent dependency:

If cloned using Manifest File,

# Enter the Data Store directory
cd IEdgeInsights/DataStore

If cloned Data Store repo directly

# Enter the Data Store directory
cd applications.industrial.edge-insights.data-store

Note: Ensure that docker ps is clean and docker network ls must not have EII bridge network.

Update local_env file for the following:
1. ETCD_HOST variables with your system IP.
2. `READ_CONFIG_FROM_FILE_ENV` value to `true` and `DEV_MODE` value to `true`.
3. Set the values for 'INFLUXDB_USERNAME', 'INFLUXDB_PASSWORD', 'MINIO_ACCESS_KEY', 'MINIO_SECRET_KEY' which are InfluxDB and Minio DB credentials

Source the local_env using the following command:
set -a && source local_env && set +a

Set Write Permission for Data Dir(Volume Mount paths): This is required for Database Server to have write permission to the respective storage paths.
sudo mkdir -p $EII_INSTALL_PATH/data
sudo chmod 777 $EII_INSTALL_PATH/data
sudo chown -R eiiuser:eiiuser $EII_INSTALL_PATH/data
# Run the service
docker compose -f docker-compose.yml -f docker-compose-dev.override.yml up -d

Note: Data Store container restarts automatically when its config is modified in the config.json file. If you update the config.json file by using vi or vim editor, it is required to append the set backupcopy=yes in ~/.vimrc so that the changes done on the host machine config.json are reflected inside the container mount point.

Deploy Data Store Service with Config Manager Agent Dependency

Run the following commands to deploy the Data Store Service with Config Manager Agent dependency:

Note: Ensure that the Config Manager Agent image present in the system. If not, build the Config Manager Agent locally when independently deploying the service with Config Manager Agent dependency.

# Enter the Data Store directory
cd IEdgeInsights/DataStore

Source the local_env file which consist of all the EII envs needed to build datastore independently

sh
set -a && source local_env && set +a

Note: Ensure that docker ps is clean and docker network ls doesn’t have EII bridge networks.

Update local_env file for following:
1. HOST_IP and ETCD_HOST variables with your system IP.
2. `READ_CONFIG_FROM_FILE_ENV` value is set to `false`.
3. Set the values for 'INFLUXDB_USERNAME', 'INFLUXDB_PASSWORD', 'MINIO_ACCESS_KEY', 'MINIO_SECRET_KEY' which are InfluxDB and MinIO object storage credentials

Copy the docker-compose.yml from IEdgeInsights/ConfigMgrAgent as docker-compose.override.yml in IEdgeInsights/DataStore.

cp ../ConfigMgrAgent/docker-compose.yml docker-compose.override.yml

Copy the builder.py with standalone mode changes from IEdgeInsights/build directory

cp ../build/builder.py .

Run the builder.py in standalone mode, this will generate eii_config.json and update docker-compose.override.yml

python3 builder.py -s true

Building the service (This step is optional for building the service if not already done in the Independently buildable step above)

docker compose build

For running the service in PROD mode, run the below command:

NOTE: Make sure to update DEV_MODE to false in local_env while running in PROD mode and source the local_env using the command set -a && source local_env && set +a.

docker compose up -d

For running the service in DEV mode, run the below command:

NOTE: Make sure to update DEV_MODE to true in local_env while running in DEV mode and source the local_env using the command set -a && source local_env && set +a.

docker compose -f docker-compose.yml -f docker-compose-dev.override.yml -f docker-compose.override.yml up -d

Data Store Configuration

The configurations for Data Store Service are added in etcd. The configuration details are available in the docker-compose file, under AppName in the environment section of the app’s service definition.

For the scenario, when the AppName is DataStore, the following example shows how the app’s config will look for /DataStore/config key in etcd:

"datatypes": {
  "json": {
       "host" : "ia_influxdb",
       "port": 8086,
       "dbname": "datain",
       "verifySsl": false,
       "ignoreKeys": [
         "defects"
       ],
       "tagKeys": [],
       "retention": "1h",
       "topics": [
         "*"
       ],
       "retentionPollInterval": "60s"
   },
  "blob": {
       "host" : "ia_miniodb",
       "port": 9000,
       "dbname": "image-store-bucket",
       "retention": "1h",
       "topics": [
         "edge_video_analytics_results"
       ],
       "retentionPollInterval": "60s",
       "ignoreKeys": [
         "model-registry"
       ]
  }
},
"dbs": {
   "json": "influxdb",
   "blob": "miniodb"
}

The following are the details of the keys in the above config: - datatype (required) - The host is optional parameter in configuration, which is used for connecting the respective Database servers (Local/Remote). If the parameter is not provided, by default JSON Datatype will be selected with ia_influxdb and Blob Datatype will be selected with ia_miniodb - The port is optional parameter in configuration, which is used for connecting the respective Database servers port(Local/Remote). If the parameter is not provided, by default JSON Datatype will be selected with 8086 for Influx DB and Blob Datatype will be selected with 9000 for Minio Object Storage - The topics key determines which messages are to be processed by the corresponding DB microservice. Only the messages with a topic listed in topics key are processed by the individual module. If topics contain \*, then all the messages are processed. - The retention is required parameter in configuration. The retention parameter specifies the retention policy to apply for the images stored in MinIO object storage. In case of infinite retention time, set it to ““. Suitable duration string value as mentioned at https://golang.org/pkg/time/#ParseDuration. - The retentionPollInterval is required parameter in configuration. Used to set the time interval for checking images for expiration. Expired images will become candidates for deletion and no longer retained. In case of infinite retention time, this attribute will be ignored. Suitable duration string value as mentioned at https://golang.org/pkg/time/#ParseDuration - The ignoreKeys is list of string which allows to add keys. For JSON, this list will be used parser to choose whether to parse the nested json or save as string to database. For BLOB, this list will be used for not applying the retention policy for the respective buckets.

  • dbs (Optional)

    • The json is optional parameter in dbs configuration, which is used for selection of db for JSON(Metadata) Datatype. Options available are influxdb

    • The blob is optional parameter in dbs configuration, which is used for selection of db for BLOB Datatype. Options available are miniodb

  • restserver

    • The Port key is used to configure the port exposed to access the REST APIs. > Note: Same should be updated under Port section indocker-compose.yml

    • The cacertname key is filename of pem certificate

    • The caprivatekey key is filename of pem key

    To use different certificates for restserver change the LHS of the volume mount path in docker-compose.yml for line item ./Certificates/DataStore_Server/:/run/secrets/RestAPI_Server:ro, update the cacertname and caprivatekey with respective file names in config.json.

    Refer REST API Interface for details of REST APIs. Swagger(API Documentation) is available at /docs. To access swagger, after starting data store open browser and enter url https://<ip>:8080. For DEV_MODE as true, use http://<ip>:8080

By default, both the DBs will be enabled. If you want to disable any of the above DBs, remove the corresponding key and its value from the config.

For Example, if you are not using MinIO object storage, you can disable the same and modify the config as below:

"datatypes": {
  "json": {
       "host" : "ia_influxdb",
       "port": 8086,
       "dbname": "datain",
       "verifySsl": false,
       "ignoreKeys": [
         "defects"
       ],
       "tagKeys": [],
       "retention": "1h",
       "topics": [
         "*"
       ],
       "retentionPollInterval": "60s"
   }
}

For Backuping up the Json and Blob data following configuration is provided in config.json

"storage": {
  "enabled": false,
  "type": "local",
  "autoSyncIntervalInSec": 3600,
  "blobIdentifier": "img_handle"
}

NOTE: Enabling storage feature with type local as above will backup both json and blob data which would lead to high disk space consumption on the host system and the consumption will be more in case of multi streams.For example 1hr of data for a single stream with image resolution as 1920 * 1200 consumes 3.1Gb of disk space.

The following are the details of the keys in the above config:

  • The enabled is by default false but if the backup of data is needed then set the enabled flag as true.

  • The type denotes the type of storage needed i.e. either local or cloud.

  • The autoSyncIntervalInSec denotes the time interval in seconds indicating how often the database had to be queried to backup the data.

  • The blobIdentifier denotes the identifier used for BLOB data. For example below is a Edge Video Analytics Microservice’s data snipet where the blobIdentifier will be img_handle

{'height': 1200, 'width': 1920, 'channels': 3, 'img_handle': 'cd3a30e5c3', 'defects': [], 'encoding_type': 'jpeg', 'encoding_level': 95}

NOTE 1. The backed up data is stored at /opt/intel/eii/data/ds_backup/ folder which consist of two subfolder one for json data and one for blob data. 2. The json data is stored in the json format with filename is made up of *.json i.e edge_video_analytics_results_2024-01-23-14_44_58.json 3. For blob data the format is taken from ‘encoding_type’ field of Edge Video Analytics Microservice’s data with file name is made up of *. and blob data is stored in the folder blob/ i.e blob/2024-02-01-16:25:32/edge_video_analytics_results_ff875f1df.jpeg

JSON Datatype (InfluxDB)

For nested json data, by default, Data Store will flatten the nested json and push the flat data to InfluxDB to avoid the flattening of any particular nested key mention the tag key in the config.json file. Currently the defects key is ignored from flattening. Every key to be ignored has to be in a new line.

For example,

ignore_keys = [ "Key1", "Key2", "Key3" ]

By default, all the keys in the data schema will be pushed to InfluxDB as fields. If tags are present in data schema, it can be mentioned in the config.json file then the data pushed to InfluxDB, will have fields and tags both. At present, no tags are visible in the data scheme and tag_keys are kept blank in the config file.

For Example,

tag_keys = [ "Tag1", "Tag2" ]

Blob Datatype (MinIO Object Storage)

The MinIO object storage primarily subscribes to the stream that comes out of the EdgeVideoAnalayticsMicroservice app via EII messagebus and stores the frame into minio for historical analysis.

The high-level logical flow of MinIO object storage is as follows:

  1. The EII messagebus subscriber in MinIO object storage will subscribe to the EdgeVideoAnalayticsMicroservice published classified result (metadata, frame) on the EII messagebus. The img_handle is extracted out of the metadata and is used as the key and the frame is stored as a value for that key in minio persistent storage.

EII Msgbus Interface

  • Data Store will start the EII messagebus Publisher, EII messagebus Subscriber threads, and EII messagebus request reply thread based on PubTopics, SubTopics and Server configuration.

  • EII messagebus Subscriber thread connects to the PUB socket of EII messagebus on which the data is published by EdgeVideoAnalayticsMicroservice and push it to the InfluxDB(Metadata).

  • EII messagebus Publisher thread will publish the point data ingested by the telegraf and the classifier result coming out of the point data analytics.

EII Msgbus Request-Response Interface

For a historical analysis of the stored classified images or metadata, Data Store starts a EII Messagebus/gRPC Request-Response Interface server which provides the read, write, update, list, delete interfaces.

The payload format are defined in EII Msgbus/gRPC Request-Response Endpoints

Note: 1. The gRPC request-response interface server currently supports DEV mode only.

DB Server Supported Version

Currently DB Handlers are supported and tested with below mentioned version for respective DB Server S.No | DB Server | Supported Version — | — | — 1 | Influx | 1.8.7 2 | Minio | RELEASE.2020-12-12T08-39-07Z