microsoft / azure-gradle-plugins

Azure Plugins for Gradle
MIT License
45 stars 28 forks source link

The option "allowTelemetry" has no effect #166

Closed enaess closed 1 year ago

enaess commented 1 year ago

It's great that you should be able to turn off the telemetry option via gradle extension

azureFunctions {
   allowTelemetry = false 
}

Though the option doesn't seem to work. When I specify this snippet in the my build.gradle file, it still sends requests to Microsoft:

This is the output for my squid cache:

1689197789.908    127 172.21.0.1 NONE_NONE/200 0 CONNECT dc.services.visualstudio.com:443 - HIER_DIRECT/40.78.253.199 -
1689197789.990    108 172.21.0.1 NONE_NONE/200 0 CONNECT dc.services.visualstudio.com:443 - HIER_DIRECT/40.78.253.199 -
1689197789.991     82 172.21.0.1 TCP_MISS/200 619 POST https://dc.services.visualstudio.com/v2/track - HIER_DIRECT/40.78.253.199 application/json
1689197790.077     85 172.21.0.1 TCP_MISS/200 619 POST https://dc.services.visualstudio.com/v2/track - HIER_DIRECT/40.78.253.199 application/json

Inspecting the AzureFunctionsPlugin.java, I find through code inspection that the option cannot possibly work (I've also stepped through the debugger to verify this).

   public void apply(Project project) {
        JoinPoint var8 = Factory.makeJP(ajc$tjp_0, this, this, project);

        try {
            AzureOperationAspect.aspectOf().beforeEnter(var8);
            AzureTaskManager.register(new GradleAzureTaskManager());
            AzureMessager.setDefaultMessager(new GradleAzureMessager(project.getLogger()));
            AzureFunctionsExtension extension = (AzureFunctionsExtension)project.getExtensions().create("azurefunctions", AzureFunctionsExtension.class, new Object[]{project});
            TelemetryAgent.getInstance().initTelemetry("azure-functions-gradle-plugin", (String)StringUtils.firstNonBlank(new String[]{AzureFunctionsPlugin.class.getPackage().getImplementationVersion(), "develop"}), BooleanUtils.isNotFalse(extension.getAllowTelemetry()));
            TelemetryAgent.getInstance().showPrivacyStatement();

            try {
                CacheManager.evictCache("<ALL>", "<ALL>");
            } catch (ExecutionException var11) {
            }

            Azure.az().config().setLogLevel(HttpLogDetailLevel.NONE.name());
            Azure.az().config().setUserAgent(TelemetryAgent.getInstance().getUserAgent());
            TaskContainer tasks = project.getTasks();
            TaskProvider packageTask = tasks.register("azureFunctionsPackage", PackageTask.class, (task) -> {
                task.setGroup("AzureFunctions");
                task.setDescription("Package current project to staging folder.");
                task.setFunctionsExtension(extension);
            });
...

While the extension is indeed registered, it is not populated with values until project is configured, e.g. project.afterEvaluate(), and the initialization of the TelemetryAgent occurs prior to any evaluation of the azureFunctions { } closure. At this point, the value of allowTelemetry in the extension object always evaluates to null, which the BooleanUtils.isNotFalse() evaluates to true (!isFalse(null) is true).

Anyhow, I'd like to be able to disable the telemetry option from my builds. Also, another aspect of this could be to embed (or allow a user to run ./gradlew -Pcom.microsoft.azure.allowTelemetry=false on the command line alternatively set it in gradle.properties).

Also, it maybe good to change the AzureFunctionExtension to use Property<> API with Gradle to allow for Lazy initialization. See here: https://docs.gradle.org/current/userguide/lazy_configuration.html

It would allow tasks you register to connect with the properties of the extension, but let the evaluation of these happen if the task is actually realized.

enaess commented 1 year ago

@wangmingliang-ms You have any updates on this, I created a Pull Request, but seems like nobody at Microsoft is watching this project???

Flanker32 commented 1 year ago

@enaess Thanks a lot for your effort and really sorry for the late response. I've merged your fix,and will release the fix asap

Flanker32 commented 1 year ago

@enaess Thanks again for your help, we have released gradle functions plugin 1.13.1 and gradle webapp plugin 1.8.1 which including your fixes. Please feel free to contact us once you meet any other issues!

enaess commented 1 year ago
        Azure.az().config().setLogLevel(HttpLogDetailLevel.NONE.name());
        Azure.az().config().setUserAgent(TelemetryAgent.getInstance().getUserAgent());

@Flanker32 Looks like the plugin still references the getUserAgent() from within the TelemetryAgent instance. Though, without the TelemetryAgent intialized at this point, the UserAgent string is null/null which is probably not what you want. However, if this Telemetry agent is disabled, this shouldn't have any impact. When it is enabled, I am not sure if that is what you want.

enaess commented 1 year ago
1697482319.290    191 172.21.0.1 NONE_NONE/200 0 CONNECT dc.services.visualstudio.com:443 - HIER_DIRECT/52.175.198.74 -
1697482319.324    126 172.21.0.1 NONE_NONE/200 0 CONNECT dc.services.visualstudio.com:443 - HIER_DIRECT/52.175.198.74 -
1697482319.353     58 172.21.0.1 TCP_MISS/200 619 POST https://dc.services.visualstudio.com/v2/track - HIER_DIRECT/52.175.198.74 application/json
1697482319.364     38 172.21.0.1 TCP_MISS/200 619 POST https://dc.services.visualstudio.com/v2/track - HIER_DIRECT/52.175.198.74 application/json
1697482319.388    290 172.21.0.1 NONE_NONE/200 0 CONNECT rt.services.visualstudio.com:443 - HIER_DIRECT/23.100.122.113 -
1697482319.452     62 172.21.0.1 TCP_MISS/200 499 POST https://rt.services.visualstudio.com/QuickPulseService.svc/ping? - HIER_DIRECT/23.100.122.113 -
1697482324.678    223 172.21.0.1 NONE_NONE/200 0 CONNECT rt.services.visualstudio.com:443 - HIER_DIRECT/23.100.122.113 -
1697482324.744     64 172.21.0.1 TCP_MISS/200 499 POST https://rt.services.visualstudio.com/QuickPulseService.svc/ping? - HIER_DIRECT/23.100.122.113 -

Apparently, upgrading to 1.13.1 didn't fix my problem. I don't know why gradle is still is trying to reach out to the URLs. It seems like the code DefaultQuickPulseDataFetcher is somehow enabled (maybe statically) in the code to to collect and send data to Microsoft??? I have no idea ...