Passing configurations to a Kelvin App
In addition to receiving data, configurations are often required by the application to correctly operate. In this section, configuration injection through the application configuration file will be explained.
Defining configurations¶
The application configuration section is defined by a dictionary and can take any values. The following highlighed lines contain a configuration exemple with complex values.
app:
kelvin:
inputs:
- data_type: raw.float32
name: random_value
sources:
- asset_names: [ ]
workload_names: [ ]
configuration:
enabled: true
inside: 0
outside: 45
thresholds:
min: 20
max: 30
language:
python:
entry_point: my_app.my_app:App
requirements: requirements.txt
type: python
logging_level: INFO
version: 4.0.0
system_packages: [ ]
type: kelvin
info:
description: my-app
name: my-app
title: my-app
version: 1.0.0
spec_version: 1.0.0
Handling the configurations in the application code¶
Once specified, configurations will be available in the code. Configurations are accessible in code through Kelvin App's
self.config variable.
This instance variable holds the configuration object for quick access.
from kelvin.app import DataApplication
from kelvin.message.raw import Float32
class App(DataApplication):
"""Application."""
def process(self):
random_value = self.data.get('random_value')
min_threshold = self.config.thresholds.min
max_threshold = self.config.thresholds.max
if random_value and min_threshold <= random_value <= max_threshold:
print("The provided random value respects both thresholds")