Skip to content

Commit 35c216a

Browse files
#1955378: [Test] NPE when start streaming log for an un-deployed function app
1 parent b526203 commit 35c216a

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.appservice/src/com/microsoft/azure/toolkit/eclipse/functionapp/logstreaming/FunctionAppLogStreamingHandler.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,18 @@ private static String getApplicationInsightLiveMetricsUrl(ApplicationInsight tar
9898
}
9999

100100
private static boolean isLogStreamingEnabled(FunctionAppBase<?, ?, ?> functionApp) {
101-
return functionApp.getRuntime().getOperatingSystem() == OperatingSystem.LINUX ||
102-
Optional.ofNullable(functionApp.getDiagnosticConfig()).map(DiagnosticConfig::isEnableWebServerLogging).orElse(false);
101+
final OperatingSystem operatingSystem = Optional.ofNullable(functionApp.getRuntime())
102+
.map(r -> r.getOperatingSystem()).orElse(null);
103+
final boolean isEnableApplicationLog = Optional.ofNullable(functionApp.getDiagnosticConfig())
104+
.map(DiagnosticConfig::isEnableApplicationLog).orElse(false);
105+
return operatingSystem == OperatingSystem.LINUX || isEnableApplicationLog;
103106
}
104107

105108
private static void enableLogStreaming(FunctionAppBase<?, ?, ?> functionApp) {
106-
final DiagnosticConfig diagnosticConfig = functionApp.getDiagnosticConfig();
109+
final DiagnosticConfig diagnosticConfig = Optional.ofNullable(functionApp.getDiagnosticConfig()).orElseGet(DiagnosticConfig::new);
107110
diagnosticConfig.setEnableApplicationLog(true);
108-
if (functionApp instanceof FunctionApp) {
109-
final FunctionAppDraft draft = (FunctionAppDraft) ((FunctionApp) functionApp).update();
110-
draft.setDiagnosticConfig(diagnosticConfig);
111-
draft.updateIfExist();
112-
}
111+
final FunctionAppDraft draft = (FunctionAppDraft) functionApp.update();
112+
draft.setDiagnosticConfig(diagnosticConfig);
113+
draft.commit();
113114
}
114115
}

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.appservice/src/com/microsoft/azure/toolkit/eclipse/webapp/handlers/WebAppLogStreamingHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private static boolean isLogStreamingEnabled(WebAppBase<?, ?, ?> webApp) {
5454
}
5555

5656
private static void enableLogStreaming(WebAppBase<?, ?, ?> webApp) {
57-
final DiagnosticConfig diagnosticConfig = webApp.getDiagnosticConfig();
57+
final DiagnosticConfig diagnosticConfig = Optional.ofNullable(webApp.getDiagnosticConfig()).orElseGet(DiagnosticConfig::new);
5858
diagnosticConfig.setEnableWebServerLogging(true);
5959
diagnosticConfig.setWebServerLogQuota(35);
6060
diagnosticConfig.setWebServerRetentionPeriod(0);

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-appservice/src/main/java/com/microsoft/azure/toolkit/intellij/legacy/appservice/AppServiceStreamingLogManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public boolean isLogStreamingEnabled() {
161161
final OperatingSystem operatingSystem = Optional.ofNullable(functionApp.getRuntime()).map(Runtime::getOperatingSystem).orElse(null);
162162
final boolean isEnableApplicationLog = Optional.ofNullable(functionApp.getDiagnosticConfig())
163163
.map(DiagnosticConfig::isEnableApplicationLog).orElse(false);
164-
return operatingSystem == OperatingSystem.LINUX || functionApp.getDiagnosticConfig().isEnableApplicationLog();
164+
return operatingSystem == OperatingSystem.LINUX || isEnableApplicationLog;
165165
}
166166

167167
@Override

0 commit comments

Comments
 (0)