Local Function¶
In enterprise systems, data from multiple sources intertwines. To effectively manage this data, it is essential to define clear business responsibility scopes for the reported data. Given that business data is constantly in a state of flux, it becomes crucial to query and retrieve associated data results based on the latest business management scopes.
TrueWatch provides the Local Function feature, allowing third-party users to fully utilize the local cache and local file management service interfaces of Function. By combining the business relationships of relevant responsible parties, users can perform data analysis queries within the workspace and easily obtain performance analysis data such as interface latency related to business relationships.
Configuration¶
Edit Local Function¶
-
Input business correspondences through the Function local cache/local file;
-
Create a Category=function script, define business parameter scopes, and write data query statements (DQL + business relationship table);
-
Publish the function script.
Editing Example¶
import time
@DFF.API('Data Query Function', category='dataPlatform.dataQueryFunc')
def query_fake_data(time_range=None, tier=None):
# TrueWatch Connector
dataPlatform = DFF.CONN('dataPlatform')
# If no time range is specified, force it to the last 1 minute of data
if not time_range:
now = int(time.time())
time_range = [
(now - 60) * 1000,
(now - 0) * 1000,
]
# DQL Statement
dql = 'M::`fake_data_for_test`:(avg(`field_int`)) BY `tag`'
# Append conditions based on the additional parameter tier
conditions = None
if tier == 't1':
conditions = 'tag in ["value-1", "value-3"]'
elif tier == 't2':
conditions = 'tag = "value-2"'
# Query and return data in raw form
status_code, result = dataPlatform.dataway.query(dql=dql, conditions=conditions, time_range=time_range, raw=True)
return result
Use the Function to Retrieve Query Results¶
-
Go to Console > Scenarios > Chart Query, and select Add Data Source;
-
Select the edited Function and fill in the parameters;
-
Display the query results: