func FromLabelValueEntityIDGenerator(key, label string) definition.EntityIDGeneratorFunc {
	return func(groupLabel string, rawEntityID string, g definition.RawGroups) (string, error) {
		v, err := FromLabelValue(key, label)(groupLabel, rawEntityID, g)
		if err != nil {
			return "", fmt.Errorf("cannot fetch label %q for metric %q: %w", label, key, err)
		}
		if v == nil {
			return "", fmt.Errorf("unexpected nil value of fetched data for metric %q", key)
		}
		val, ok := v.(string)
		if !ok {
			return "", fmt.Errorf("incorrect type %T of fetched data for metric %q", v, key)
		}
		return val, err
	}
}
FromLabelValueEntityIDGenerator generates an entityID using the value of the specified label
for the given metric key.
package prometheus
import (
	"errors"
	"fmt"
	"math"
	"sort"
	"strconv"
	"strings"
	model "github.com/prometheus/client_model/go"
	"github.com/newrelic/nri-kubernetes/v2/src/definition"
)
var ControlPlaneComponentTypeGenerator = func(
	groupLabel string,
	_ string,
	_ definition.RawGroups,
	clusterName string,
) (string, error) {
	return fmt.Sprintf("k8s:%s:controlplane:%s", clusterName, groupLabel), nil
}
var FromRawEntityIDGenerator = func(_, rawEntityID string, _ definition.RawGroups) (string, error) {
	return rawEntityID, nil
}
func FromLabelValueEntityTypeGenerator(key string) definition.EntityTypeGeneratorFunc {
	return func(groupLabel string, rawEntityID string, g definition.RawGroups, clusterName string) (string, error) {
		switch groupLabel {
		case "namespace", "node":
			return fmt.Sprintf("k8s:%s:%s", clusterName, groupLabel), nil
		case "container":
			labels, err := getLabels(groupLabel, rawEntityID, key, g, "namespace", "pod")
			if err != nil {
				return "", err
			}
			if len(labels) != 2 {
				return "", fmt.Errorf("cannot retrieve values for composing entity type for %q", groupLabel)
			}
			namespace := labels[0]
			podName := labels[1]
			if namespace == "" || podName == "" {
				return "", fmt.Errorf("empty values for generated entity type for %q", groupLabel)
			}
			return fmt.Sprintf("k8s:%s:%s:%s:%s", clusterName, namespace, podName, groupLabel), nil
		default:
			labels, err := getLabels(groupLabel, rawEntityID, key, g, "namespace")
			if err != nil {
				return "", err
			}
			if len(labels) == 0 {
				return "", fmt.Errorf("cannot retrieve values for composing entity type for %q", groupLabel)
			}
			namespace := labels[0]
			if namespace == "" {
				return "", fmt.Errorf("empty namespace for generated entity type for %q", groupLabel)
			}
			return fmt.Sprintf("k8s:%s:%s:%s", clusterName, namespace, groupLabel), nil
		}
	}
}
func getLabels(groupLabel, rawEntityID, key string, groups definition.RawGroups, labels ...string) ([]string, error) {
	var s []string
	for _, label := range labels {
		v, err := FromLabelValue(key, label)(groupLabel, rawEntityID, groups)
		if err != nil {
			return s, fmt.Errorf("cannot fetch label %q for metric %q: %w", label, key, err)
		}
		if v == nil {
			return s, fmt.Errorf("label %q not found for metric %q", label, key)
		}
		val, ok := v.(string)
		if !ok {
			return s, fmt.Errorf("unexpected type %T of label %q for metric %q", v, label, key)
		}
		s = append(s, val)
	}
	return s, nil
}