public String buildQuery(
      CanaryConfig canaryConfig,
      SignalFxCanaryMetricSetQueryConfig queryConfig,
      CanaryScope canaryScope,
      SignalFxScopeConfiguration scopeConfiguration,
      SignalFxCanaryScope signalFxCanaryScope) {

    String aggregationMethod =
        Optional.ofNullable(queryConfig.getAggregationMethod()).orElse("mean");
    List<QueryPair> queryPairs =
        Optional.ofNullable(queryConfig.getQueryPairs()).orElse(new LinkedList<>());

    String[] baseScopeAttributes = new String[] {"scope", "location"};

    try {
      String customFilter =
          QueryConfigUtils.expandCustomFilter(
              canaryConfig, queryConfig, canaryScope, baseScopeAttributes);

      return Optional.ofNullable(customFilter)
          .orElseGet(
              () ->
                  getSimpleProgram(
                      queryConfig,
                      scopeConfiguration,
                      signalFxCanaryScope,
                      aggregationMethod,
                      queryPairs));
    } catch (Exception e) {
      throw new RuntimeException("Failed to generate SignalFx SignalFlow program", e);
    }
  }
@Test
  public void test_inline_template_supplied() {
    String customInlineTemplate =
        "data('request.count', filter="
            + "filter('server_group', 'my_microservice-control-v1'))"
            + ".mean(by=['server_group']).publish()";

    CanaryConfig canaryConfig = CanaryConfig.builder().build();
    SignalFxCanaryMetricSetQueryConfig metricSetQueryConfig =
        SignalFxCanaryMetricSetQueryConfig.builder()
            .customInlineTemplate(customInlineTemplate)
            .build();
    CanaryScope canaryScope = CanaryScope.builder().build();
    SignalFxScopeConfiguration scopeConfiguration = SignalFxScopeConfiguration.builder().build();
    SignalFxCanaryScope scope = new SignalFxCanaryScope();

    String expected =
        "data('request.count', filter="
            + "filter('server_group', 'my_microservice-control-v1'))"
            + ".mean(by=['server_group']).publish()";

    assertEquals(
        expected,
        signalFxQueryBuilderService.buildQuery(
            canaryConfig, metricSetQueryConfig, canaryScope, scopeConfiguration, scope));
  }