func()

in custom-metrics-stackdriver-adapter/pkg/adapter/translator/query_builder.go [335:374]


func (qb QueryBuilder) validate() error {
	if qb.translator == nil {
		return apierr.NewInternalError(fmt.Errorf("QueryBuilder tries to build with translator value: nil"))
	}

	if !qb.nodes.isNodeValuesEmpty() {
		// node metric
		if !qb.nodes.isNodeValuesValid() {
			return apierr.NewInternalError(fmt.Errorf("invalid nodes parameter is set to QueryBuilder"))
		}
		if qb.namespace != "" {
			return apierr.NewInternalError(fmt.Errorf("both nodes and namespace are provided, expect only one of them."))
		}
		if !qb.pods.isPodValuesEmpty() {
			return apierr.NewInternalError(fmt.Errorf("both nodes and pods are provided, expect only one of them."))
		}
	} else {
		// pod metric
		if qb.pods.isPodValuesEmpty() {
			return apierr.NewInternalError(fmt.Errorf("no resources are specified for QueryBuilder, expected one of nodes or pods should be used"))
		}
		if !qb.pods.isPodValuesValid() {
			return apierr.NewInternalError(fmt.Errorf("invalid pods parameter is set to QueryBuilder"))
		}
		numPods := len(qb.pods.getQuotedPodNames())
		if numPods > MaxNumOfArgsInOneOfFilter {
			return apierr.NewInternalError(fmt.Errorf("QueryBuilder tries to build with %v pod list, but allowed limit is %v pods", numPods, MaxNumOfArgsInOneOfFilter))
		}
	}

	if qb.metricValueType == "DISTRIBUTION" && !qb.translator.supportDistributions {
		return apierr.NewBadRequest("distributions are not supported")
	}

	if qb.enforceContainerType && !qb.translator.useNewResourceModel {
		return apierr.NewInternalError(fmt.Errorf("illegal state! Container metrics works only with new resource model"))
	}

	return nil
}