@Override
    public SeriesSpec apply(final Metric metric) {
        metricValidator.validate(metric);

        return switch (metric.functionName()) {
            case Average.NAME -> Average.builder().field(metric.fieldName()).build();
            case Cardinality.NAME -> Cardinality.builder().field(metric.fieldName()).build();
            case Count.NAME -> Count.builder().field(metric.fieldName()).build();
            case Latest.NAME -> Latest.builder().field(metric.fieldName()).build();
            case Max.NAME -> Max.builder().field(metric.fieldName()).build();
            case Min.NAME -> Min.builder().field(metric.fieldName()).build();
            case Percentage.NAME -> Percentage.builder()
                    .field(metric.fieldName())
                    .strategy(metric.configuration() != null ? ((PercentageConfiguration) metric.configuration()).strategy() : null)
                    .build();
            case Percentile.NAME -> Percentile.builder()
                    .field(metric.fieldName())
                    .percentile(((PercentileConfiguration) metric.configuration()).percentile())
                    .build();
            case StdDev.NAME -> StdDev.builder().field(metric.fieldName()).build();
            case Sum.NAME -> Sum.builder().field(metric.fieldName()).build();
            case SumOfSquares.NAME -> SumOfSquares.builder().field(metric.fieldName()).build();
            case Variance.NAME -> Variance.builder().field(metric.fieldName()).build();
            default -> Count.builder().field(metric.fieldName()).build(); //TODO: do we want to have a default at all?
        };
    }
@Test
    void throwsExceptionWhenValidatorThrowsException() {
        doThrow(ValidationException.class).when(metricValidator).validate(any());
        assertThrows(ValidationException.class, () -> toTest.apply(new Metric("unknown", "http_method")));
    }