func()

in pkg/client/elasticsearch/discovery.go [179:237]


func (r *recorder) _processMappingDocument(root string, d map[string]interface{}, fieldsSet config.FieldsSet, indices []string) {
	for k, t := range d {
		if k == "*" {
			continue
		}
		if k == "properties" {
			tm, ok := t.(map[string]interface{})
			if !ok {
				continue
			}
			r._processMappingDocument(root, tm, fieldsSet, indices)
		} else {
			// Is there a properties child ?
			child, ok := t.(map[string]interface{})
			if !ok {
				continue
			}
			if _, hasProperties := child["properties"]; hasProperties {
				var newRoot string
				if root == "" {
					newRoot = k
				} else {
					newRoot = fmt.Sprintf("%s.%s", root, k)
				}
				r._processMappingDocument(newRoot, child, fieldsSet, indices)
			} else {
				// Ensure that we have a type
				if t, hasType := child["type"]; !(hasType && isTypeAllowed(t.(string))) {
					continue
				}
				metricName := ""
				// New metric
				if root == "" {
					metricName = k
				} else {
					metricName = fmt.Sprintf("%s.%s", root, k)
				}

				fields := fieldsSet.FindMetadata(metricName)
				if fields == nil {
					// field does not match a pattern, do not register it as available
					continue
				}
				r.metrics[metricName] = provider.CustomMetricInfo{
					GroupResource: schema.GroupResource{ // TODO: infer resource from configuration
						Group:    "",
						Resource: "pods",
					},
					Namespaced: true,
					Metric:     r.namer.Register(metricName),
				}
				r.indexedMetrics[metricName] = MetricMetadata{
					Fields:  *fields,
					Indices: indices,
				}
			}
		}
	}
}