понедельник, 3 февраля 2020 г.

Switch off telemetry for Azure Cosmos DB

It is not obvious, but to switch off telemetry for Spring Data application, one should either:
  • set cosmosdb.telemetryAllowed=false in application.properties
  • set telemetryAllowed: false in application.yml
Default value is false, however sometimes it is not enough just to avoid set this property.
Surprise fro me was the need to specify it in application.yml only, even if another profile is used.

Reference:
https://github.com/microsoft/spring-data-cosmosdb/blob/master/src/main/java/com/microsoft/azure/spring/data/cosmosdb/common/PropertyLoader.java

private static final String APPLICATION_PROPERTY_FILE = "/application.properties";

private static final String APPLICATION_YML_FILE = "/application.yml";

public static boolean isApplicationTelemetryAllowed() {
    String allowed = getPropertyByName("cosmosdb.telemetryAllowed", APPLICATION_PROPERTY_FILE);

    if (allowed == null) {
        allowed = getPropertyByName("telemetryAllowed", APPLICATION_YML_FILE);
    }

    //  Default, no telemetry
    if (allowed == null) {
        return false;
    } else {
    return !allowed.equalsIgnoreCase("false");
    }
}