Local Function¶
In enterprise systems, data from multiple sources intertwine. 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 flux, it becomes particularly crucial to query and retrieve associated data results based on the latest business management scopes.
The local Function feature provided by Guance allows third-party users to fully leverage Function's local cache and local file management service interfaces. By combining these with 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 Steps¶
Edit Local Function¶
-
Input business correspondence through Function's local cache/local file;
-
Create a new Category=function script, define business parameter scopes, and write data query statements (DQL + business relationship table);
-
Publish the function script.
Edit Example¶
import time
@DFF.API('Data Query Function', category='dataPlatform.dataQueryFunc')
def query_fake_data(time_range=None, tier=None):
# Guance 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 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 This Function to Get Query Results¶
-
Go to the console > Scenarios > Chart Query, select Add Data Source;
-
Choose the already edited Function and fill in the parameter content;
-
Display the query results:
