In the previous chapter, Device Configuration Management, we explored how device configurations such as log upload and telemetry settings are dynamically generated based on device context and rules evaluation. Now, we focus on Telemetry Profiles, an abstraction that manages telemetry configurations and profiles, including the retrieval and evaluation of telemetry rules. This chapter will guide you to understand how telemetry profiles work and how to use them effectively.
Telemetry Profiles allow xconfwebconfig to define and manage how telemetry data is collected, processed, and reported for devices. These profiles play a crucial role in ensuring that devices send their telemetry data in a structured and predictable manner. Telemetry Profiles must be tailored to match the device’s context, such as its model, environment, or application type.
Imagine a scenario where a set-top box (STB) requests its telemetry configuration. The telemetry profile must specify:
- Collection Frequency: How often telemetry data should be collected.
- Telemetry Parameters: What data should be included in the report, such as logs or metrics.
- Upload Protocol and Repository: Where and how the telemetry data should be uploaded.
This configuration needs to be dynamically generated based on the device’s context, ensuring that telemetry profiles are optimized for specific environments (e.g., DEV, PROD) and device models.
A Telemetry Profile is a structured configuration that defines how telemetry data is collected and reported. It includes:
- Schedule: Specifies when telemetry data should be collected and uploaded (e.g., every 15 minutes).
- Parameters: Defines the specific telemetry data to be collected (e.g., logs, events, metrics).
- Upload Settings: Specifies the repository URL and protocol used to upload telemetry data.
{
"id": "profile_123",
"name": "Telemetry Profile for PROD",
"schedule": "*/15 * * * *",
"uploadRepository": "https://telemetry-repo.example.com",
"uploadProtocol": "HTTP"
}Telemetry Rules are logical conditions used to determine which telemetry profile applies to a device. These rules are evaluated using the device’s context and may include:
- Conditions: Checks such as
model = MODEL_XYZorenv = PROD. - Actions: Specifies the telemetry profile to associate with the rule.
{
"id": "rule_123",
"name": "Telemetry Rule for MODEL_XYZ",
"condition": {
"freeArg": {
"type": "STRING",
"name": "model"
},
"operation": "IS",
"fixedArg": {
"value": "MODEL_XYZ"
}
},
"boundTelemetryId": "profile_123"
}Telemetry Profiles can be categorized into:
- Temporary Profiles: Created dynamically based on specific conditions and are valid for a limited duration.
- Permanent Profiles: Predefined profiles stored in the database and applied based on rules.
To fetch the telemetry profile for a specific device context, use the GetTelemetryForContext method. This method evaluates the context map and retrieves the matching profile.
context := map[string]string{
"model": "MODEL_XYZ",
"env": "PROD",
"applicationType": "STB",
}
telemetryProfileService := telemetry.NewTelemetryProfileService()
telemetryProfile := telemetryProfileService.GetTelemetryForContext(context)- Input: The
contextmap contains information about the device (e.g.,model,env). - Output: The
telemetryProfileobject contains the telemetry configuration for the device.
Once the telemetry profile is retrieved, it can be used to configure the device.
if telemetryProfile != nil {
fmt.Printf("Telemetry Profile ID: %s\n", telemetryProfile.ID)
fmt.Printf("Schedule: %s\n", telemetryProfile.Schedule)
fmt.Printf("Repository URL: %s\n", telemetryProfile.UploadRepository)
} else {
fmt.Println("No matching telemetry profile found.")
}- If a profile is found, its details are printed.
- If no profile matches the context, the output informs the user.
Temporary telemetry profiles can be dynamically created based on specific conditions.
telemetryProfile := logupload.TelemetryProfile{
ID: "temp_profile_001",
Name: "Temporary Profile",
Schedule: "*/30 * * * *",
UploadRepository: "https://temp-repo.example.com",
UploadProtocol: "HTTP",
}
telemetryProfileService.CreateTelemetryProfile("model", "MODEL_XYZ", telemetryProfile)- Input: A telemetry profile is created for devices where
model = MODEL_XYZ. - Action: The profile is stored temporarily and can be retrieved later.
The workflow for fetching telemetry profiles based on device context is illustrated below:
sequenceDiagram
participant Device as Device Context
participant Service as Telemetry Profile Service
participant Rules as Telemetry Rules Engine
participant DB as Database
Device->>Service: Request telemetry profile
Service->>Rules: Evaluate context map
Rules->>DB: Fetch telemetry rules and profiles
DB-->>Rules: Return matching rules and profiles
Rules-->>Service: Return telemetry profile
Service-->>Device: Respond with telemetry profile
The GetTelemetryForContext method retrieves the telemetry profile for a given context.
File: dataapi/dcm/telemetry/telemetry_profile.go
func (t *TelemetryProfileService) GetTelemetryForContext(context map[string]string) *logupload.TelemetryProfile {
telemetryProfile := t.GetTemporaryProfileForContext(context)
return telemetryProfile
}- First checks for a temporary profile matching the context.
- Returns the profile if found, otherwise returns
nil.
The ProcessTelemetryTwoRules method evaluates telemetry rules to determine applicable profiles.
File: dataapi/dcm/telemetry/telemetry_profile.go
func (t *TelemetryProfileService) ProcessTelemetryTwoRules(context map[string]string) []*logupload.TelemetryTwoRule {
all := logupload.GetTelemetryTwoRuleList()
ruleProcessorFactory := re.NewRuleProcessorFactory()
processor := ruleProcessorFactory.Processor
matched := []*logupload.TelemetryTwoRule{}
for _, tRule := range all {
if processor.Evaluate(&tRule.Rule, context, log.Fields{}) {
matched = append(matched, tRule)
}
}
return matched
}- Fetches all telemetry rules from the database.
- Evaluates each rule against the context map.
- Returns the matched rules.
- Define Clear Telemetry Profiles: Ensure profiles are well-structured and meet the operational requirements of the environment.
- Use Temporary Profiles Judiciously: Create temporary profiles for specific conditions and ensure they expire after their intended use.
- Log Rule Evaluations: Use detailed logs to track rule evaluation and debugging.
In this chapter, we explored Telemetry Profiles, an essential abstraction for managing telemetry configurations and profiles in xconfwebconfig. You learned how telemetry profiles are created, evaluated, and applied based on device context. This abstraction ensures devices are configured with optimal telemetry settings tailored to their environment.
Next, we will explore the Tagging System and its role in categorizing and managing devices.
Generated by AI Codebase Knowledge Builder