Skip to content

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 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 the local cache and local file management service interfaces of Function. By integrating 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

  1. Input business correspondences through the Function local cache/local file;

  2. Create a Category=function script, define business parameter scopes, and write data query statements (DQL + business relationship table);

  3. 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):
    # Guance Connector
    dataPlatform = DFF.CONN('dataPlatform')

    # When no time range is specified, force a limit 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 the Function to Retrieve Query Results

  1. Go to the Console > Scenarios > Chart Query, and select Add Data Source;

  2. Choose the already edited Function and fill in the parameter content;

  3. Display the query results:

Feedback

Is this page helpful? ×