Instrumenting RDKB components to use Telemetry2.0
Introduction
While migrating to Telemetry2.0 from DCA telemetry, the traditional log grepping is targetted to reduce as much as possible by instrumenting the markers coming from RDKB components.To achieve this, RDKB components are supposed make required changes with the use of APIs from Telemetry 2.0 shared library (commonlib – https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/telemetry/+/refs/heads/rdk-next/source/commonlib/ )
Brief Background:
In DCA telemetry, the markers fetched from xconf are grepped in log files and reported in json format to splunk server.
The markers are of 3 types:
- Split based markers.
- Count based markers
- TR-181 based markers.
Marker Type | Sample configuration from xconf | Description with respect to sample configuration |
---|---|---|
Split based markers | {"header":"WIFI_ACS_1_split","content":"WIFI_ACS_1:","type":"wifihealth.txt","pollingFrequency":"0"} | Expects the value after content “WIFI_ACS_1:” |
Count based markers | {"header":"RF_ERROR_IPV6PingFailed","content":"Ping to IPv6 Gateway Address are failed","type":"SelfHeal.txt.0","pollingFrequency":"0"} | Expects the occurance count of content “Ping to IPv6 Gateway Address are failed” |
TR-181 based markers | {“header” : “XDNS_split”,”content” : “Device.DeviceInfo.X_RDKCENTRAL-COM_EnableXDNS”,”type” : “<message_bus>”,”pollingFrequency”:”48″} | Markers whose type is configured as “<message_bus>” |
In T2.0, the aim is to instrument possible number of split and count based markers from component side. These are termed as event markers. Can be classified as one more type under the classification of markers. Once a marker is instrumented from component side, its configuration on xconf will be changed from the configured file name to “<event>” in ‘type:’ section.
Example: {“header”:”WIFI_ACS_1_split”,”content”:”WIFI_ACS_1:”,”type”:<event>”,”pollingFrequency”:”0″}
Overview of Instrumenting RDKB components with T2 shared library (commonlib) APIs:
Steps to instrument split based and count based markers from RDKB components side:
- Check if that particular device Build have the Telemtry2.0 building capability
- Include required headers
- Compile the component with telemetry 2.0 support
- Initialize the module with telemetry
- Find the correct place to report a marker
- Use appropriate APIs to report markers and values.
- Must check notes
- To check if a particular device build have the Telemtry2.0 building capability
- Should have an entry in device based.xml file
- “telemetry2_0” should be appeneded to DISTRO_FEATURES in machine configuration file. NOTE: Distro feature will be removed soon, and this page will be updated to reflect that.
- Include required headers / declare enough sized telemetry buffer and send events to T2 with t2_event_s() api
- NOTE: Now that T2.0 is present on all RDK-B platforms, there is no need to use the #if defined for the header or T2.0 API calls
#if defined(ENABLE_FEATURE_TELEMETRY2_0)
#include <telemetry_busmessage_sender.h>#endif- https://code.rdkcentral.com/r/plugins/gitiles/rdkb/components/opensource/ccsp/CcspWifiAgent/+/refs/heads/rdk-next/include/TR-181/ml/cosa_wifi_internal.h
- https://code.rdkcentral.com/r/plugins/gitiles/rdkb/components/opensource/ccsp/CcspWifiAgent/+/refs/heads/rdk-next/source/TR-181/sbapi/wifi_monitor.c
- NOTE: Now that T2.0 is present on all RDK-B platforms, there is no need to use the #if defined for the header or T2.0 API calls
- To compile a component with Telemetry2.0 if it is enabled for that device. NOTE: Distro feature will be removed soon, and this page will be updated to reflect that.
- Add depends to telemetry module.
- Add Compile time (-DENABLE_FEATURE_TELEMETRY2_0) and linking time (-ltelemetry_msgsender) flags to the recipe file.
- Make sure that bb file has below line to avoid compilation errors.
- CFLAGS_append = ” -I${STAGING_INCDIR}/ccsp “
- Sample review: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/rdk-oe/meta-rdk-broadband/+/refs/heads/rdk-next/recipes-ccsp/ccsp/ccsp-wifi-agent.bb
- Initialize the module with telemetry
- Initialization needs to be done only once at the very initial stage of application / module
- Find the correct place to report a marker
- Previously in DCA telemetry, a marker is reported based on the xconf configured “content” string – when the content string is found in corresponding configured filename configured under ‘type:’ section .
- /* Refer : {“header”: “WIFI_INFO_Hotspot_client_connected“, “content”: “Added case, Client with:“, “type”: “Hotspotlog.txt.0“,”pollingFrequency”:”0″} */
- So, find the right place where the content string is being written to the corresponding log file in order to event a marker in T2.0.
- https://code.rdkcentral.com/r/plugins/gitiles/rdkb/components/opensource/ccsp/hotspot/+/refs/heads/rdk-next/source/hotspotfd/cosa_hotspot_dml.c (Line number 144 gives the idea) CcspTraceInfo((“Added case, Client with MAC:%s will be addedn”, l_cMacAddr));
- Once the place is decided, use the right API to report Marker and values.
- For markers without “_split” suffix, the marker data is just a count of the number of times the marker is received. In this case, the t2_event_d API can be used because the marker data passed to the API is not important.
- Example: t2_event_d(“WIFI_INFO_Hotspot_client_connected”, 1); in https://code.rdkcentral.com/r/plugins/gitiles/rdkb/components/opensource/ccsp/hotspot/+/refs/heads/rdk-next/source/hotspotfd/cosa_hotspot_dml.c
- For markers with “_split” suffix, the marker data is important, so use the API most appropriate to the marker data. For instance, if the marker data is a string, use t2_event_s. But if marker data is numeric, use one of t2_event_d or t2_event_f. Also note that testing must ensure the string used for marker data matches the string expected by legacy telemetry.
- For markers without “_split” suffix, the marker data is just a count of the number of times the marker is received. In this case, the t2_event_d API can be used because the marker data passed to the API is not important.
- Previously in DCA telemetry, a marker is reported based on the xconf configured “content” string – when the content string is found in corresponding configured filename configured under ‘type:’ section .
- Use appropriate APIs to event markers and values
- In RDKB we have logs coming from both scripts and component’s code (code in C). From which markers are reported/grepped.
- List of APIs :
- To report markers from components
- t2_event_s(char* marker, char* value) – To send _split marker with string value to T2
- Usage:
- t2_event_s(“xh_mac_3_split”, “xh_MAC_value”);
- t2_event_s(“xh_mac_3_split”, strBuff); /* where strBuff contains the string value to be reported for this marker */
- NOTE: The instrumented component could use a static buffer or do a buffer malloc itself; but T2 common lib makes its own copy regardless, so instrumented component must clean up after itself.
- Usage:
- t2_event_f(char* marker, double value) – To send marker with double value to T2
- Usage: t2_event_d(“HWREV_split“, 2.2);
- t2_event_d(char* marker, int value) – To send marker with integer value to T2 (or) to report count based markers
- Usage:
- t2_event_d(“WIFI_INFO_Zero_5G_Clients”, 1); /* To report counter based markers– The value is reported as “1” */
- t2_event_d(“Total_5G_clients_split”, num_devs); /* To report integer type split markers */
- Usage:
- t2_event_s(char* marker, char* value) – To send _split marker with string value to T2
- To report markers from components
- Must Check Notes
- While instrumenting components
- If you are defining a character array buffer to store the value corresponding to marker , Make sure Maximum buffer size is allocated, And is reset with ‘ ‘ before and after its use.
- Example: “telemetryBuff” usage in https://code.rdkcentral.com/r/plugins/gitiles/rdkb/components/opensource/ccsp/CcspWifiAgent/+/refs/heads/rdk-next/source/TR-181/sbapi/wifi_monitor.c
- In many cases, an existing buffer already being built/used within the component can be used rather than necessitating creation of a new buffer; see https://code.rdkcentral.com/r/plugins/gitiles/rdkb/components/opensource/ccsp/CcspTr069Pa/+/refs/heads/rdk-next/source-embedded/DslhManagementServer/ccsp_management_server_pa_api.c
- To Report count based markers , The value should be mentioned as “1” while using t2_event_d() API.
- If you are defining a character array buffer to store the value corresponding to marker , Make sure Maximum buffer size is allocated, And is reset with ‘ ‘ before and after its use.
- While instrumenting Scripts
- Source the utility script /lib/rdk/t2Shared_api.sh
- Invoke :
- t2ValNotify “Marker” “Value” – To report split based markers
- t2CountNotify “Marker” – To report count based markers.
- https://code.rdkcentral.com/r/plugins/gitiles/rdkb/components/opensource/ccsp/sysint/+/refs/heads/rdk-next/uploadRDKBLogs.sh
- While instrumenting components