+type AppMetricsStruct struct {
+ ObjectName string
+ ObjectInstance string
+ // xxx add labels here
+}
+
+type AppMetrics map[string]AppMetricsStruct
+
+// Parses the metrics data from an array of bytes, which is expected to contain a JSON
+// array with structs of the following format:
+//
+// { ...
+// "config" : {
+// "metrics": [
+// { "name": "...", "objectName": "...", "objectInstamce": "..." },
+// ...
+// ]
+// }
+// }
+func parseMetricsFromXAppDescriptor(descriptor []byte, appMetrics AppMetrics) AppMetrics {
+ var desc []map[string]interface{}
+ json.Unmarshal(descriptor, &desc)
+
+ for _, app := range desc {
+ config, config_ok := app["config"]
+ if config_ok {
+ metrics, metrics_ok := config.(map[string]interface{})["metrics"]
+ if metrics_ok {
+ parseMetricsRules(metrics.([]interface{}), appMetrics)
+ }
+ }
+ }
+ return appMetrics
+}
+
+// Parses the metrics data from an array of interfaces, which are expected to be maps
+// of the following format:
+// { "name": xxx, "objectName": yyy, "objectInstance": zzz }
+// Entries, which do not have all the necessary fields, are ignored.
+func parseMetricsRules(metricsMap []interface{}, appMetrics AppMetrics) AppMetrics {
+ for _, element := range metricsMap {
+ name, name_ok := element.(map[string]interface{})["name"].(string)
+ if name_ok {
+ _, already_found := appMetrics[name]
+ objectName, objectName_ok := element.(map[string]interface{})["objectName"].(string)
+ objectInstance, objectInstance_ok := element.(map[string]interface{})["objectInstance"].(string)
+ if !already_found && objectName_ok && objectInstance_ok {
+ appMetrics[name] = AppMetricsStruct{objectName, objectInstance}
+ logger.Info("parsed counter %s %s %s", name, objectName, objectInstance)
+ }
+ if already_found {
+ logger.Info("skipped duplicate counter %s", name)
+ }
+ }
+ }
+ return appMetrics
+}
+
+func getRules(vespaconf *VESAgentConfiguration, xAppConfig []byte) {
+ appMetrics := make(AppMetrics)
+ parseMetricsFromXAppDescriptor(xAppConfig, appMetrics)
+