Skip to content

Commit

Permalink
Merge pull request #963 from JetBrains/rival/improve-logging
Browse files Browse the repository at this point in the history
Add more logs
  • Loading branch information
rafaelldi authored Nov 20, 2024
2 parents 66db71b + 836ce62 commit e65cdbb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class FunctionCoreToolsManager {
return null
}

LOG.trace { "Latest Functions tooling release path: $latestReleasePath " }

return latestReleasePath
}

Expand All @@ -121,6 +123,7 @@ class FunctionCoreToolsManager {
.map { it.functionsVersion }
.toMutableList()
versionsManagedByRider.add("v0")
LOG.trace { "Functions tooling managed by Rider: ${versionsManagedByRider.joinToString()}" }

val coreToolsDownloadFolder = settings.functionDownloadPath
if (coreToolsDownloadFolder.isEmpty()) {
Expand All @@ -130,7 +133,10 @@ class FunctionCoreToolsManager {
val versionsToUpdate = versionsManagedByRider.filter {
coreToolsDownloadFolderPath.resolve(it).exists()
}
if (versionsToUpdate.isEmpty()) return
if (versionsToUpdate.isEmpty()) {
LOG.trace { "Unable to find any Functions tooling versions to update" }
return
}

val toolingReleases = FunctionsToolingFeedService
.getInstance()
Expand All @@ -155,6 +161,8 @@ class FunctionCoreToolsManager {
releaseTag: String,
coreToolsDownloadFolder: Path
) {
LOG.trace { "Updating Functions tooling. Version: $functionsVersion, release: $releaseTag, folder: $coreToolsDownloadFolder" }

val coreToolsPath = coreToolsDownloadFolder.resolve(functionsVersion).resolve(releaseTag)
if (coreToolsPath.exists() && coreToolsPath.resolveFunctionCoreToolsExecutable().exists()) {
LOG.trace { "Core tools with tag $releaseTag already exists" }
Expand All @@ -170,6 +178,8 @@ class FunctionCoreToolsManager {
}

private fun cleanUpCoreToolsForVersion(functionsVersion: String, coreToolsDownloadFolder: Path) {
LOG.trace { "Cleaning Functions tooling folders. Version: $functionsVersion, download folder: $coreToolsDownloadFolder" }

val coreToolsPathForVersion = coreToolsDownloadFolder.resolve(functionsVersion)
val tagFolders = coreToolsPathForVersion.listAllTagFolders()

Expand All @@ -190,7 +200,7 @@ class FunctionCoreToolsManager {
val folderCountToDelete = tagFoldersWithoutEmpty.size - CORE_TOOLING_FOLDERS_COUNT
for (tagFolderToDelete in tagFoldersWithoutEmpty.takeLast(folderCountToDelete)) {
runCatching {
LOG.trace("Removing core tools folder $tagFolderToDelete")
LOG.trace { "Removing core tools folder $tagFolderToDelete" }
tagFolderToDelete.deleteRecursively()
}.onFailure {
LOG.trace(it)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.debug
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.diagnostic.trace
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.io.FileUtil
import com.intellij.util.execution.ParametersListUtil
Expand Down Expand Up @@ -72,6 +73,7 @@ class FunctionHostDebugLauncher(private val project: Project) {
dotNetRuntime: DotNetRuntime
): Pair<ExecutionResult, Int?> {
val temporaryPidFile = withContext(Dispatchers.IO) { createTemporaryPidFile() }
LOG.trace { "Created temporary file ${temporaryPidFile.absolutePath}" }
val programParameters = modifyProgramParameters(executable.programParameterString, temporaryPidFile)
LOG.debug { "Program parameters: $programParameters" }
val environmentVariables = modifyEnvironmentVariables(executable.environmentVariables)
Expand Down Expand Up @@ -155,6 +157,8 @@ class FunctionHostDebugLauncher(private val project: Project) {
LOG.debug("Got functions isolated worker process id from JSON output")
LOG.debug { "Functions isolated worker process id: $pidFromJsonOutput" }
return pidFromJsonOutput
} else {
LOG.debug("Unable to read process id from JSON file")
}

delay(500)
Expand All @@ -166,10 +170,20 @@ class FunctionHostDebugLauncher(private val project: Project) {
}

private suspend fun readPidFromJsonOutput(pidFile: File): Int? {
if (!pidFile.exists()) return null
if (!pidFile.exists()) {
LOG.trace { "${pidFile.absolutePath} does not exist" }
return null
}
val jsonText = withContext(Dispatchers.IO) { pidFile.readText() }
if (jsonText.isEmpty()) return null
if (jsonText.isEmpty()) {
LOG.trace { "${pidFile.absolutePath} is empty" }
return null
} else {
LOG.trace { "Content of ${pidFile.absolutePath}: $jsonText" }
}
val content = json.decodeFromString<JsonOutputFile>(jsonText)
LOG.trace { "Decoded content of ${pidFile.absolutePath}: $content" }

return content.workerProcessId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.google.gson.*
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.diagnostic.trace
import java.nio.file.Path
import kotlin.io.path.*

Expand Down Expand Up @@ -63,7 +64,7 @@ class HostJsonPatcher {
.filter { it.isNotBlank() }
.sortedBy { it }

LOG.debug("Patching " + hostJsonFile.absolutePathString() + " with function names: ${functions.joinToString(", ")}")
LOG.trace { "Patching ${hostJsonFile.absolutePathString()} with function names: ${functions.joinToString(", ")}" }
try {
val gson = GsonBuilder().setPrettyPrinting().create()
val hostJson = gson.fromJson(hostJsonFile.readText(), JsonElement::class.java).asJsonObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class FunctionsToolingFeedService : Disposable {
suspend fun downloadAndSaveReleaseFeed() = kotlin.runCatching {
if (releaseCache.isNotEmpty()) return@runCatching

LOG.trace("Downloading Functions tooling release feed")

val feed = getReleaseFeed()
val releaseTags = feed.tags
.toSortedMap()
Expand All @@ -88,9 +90,10 @@ class FunctionsToolingFeedService : Disposable {
val releaseFromTag = fixedReleases[releaseTagName] ?: releaseTag.release ?: continue
val release = feed.releases[releaseFromTag] ?: continue
val coreToolsRelease = release.findCoreToolsRelease(releaseFilter) ?: continue
LOG.debug("Release for Azure core tools version ${releaseTagName.lowercase()}: ${releaseTag.release}; ${coreToolsRelease.downloadLink}")

val releaseKey = releaseTagName.lowercase()
LOG.debug("Release for Azure core tools version ${releaseKey}: ${releaseFromTag}; ${coreToolsRelease.downloadLink}")

releaseCache.putIfAbsent(
releaseKey,
FunctionsToolingRelease(releaseKey, releaseFromTag, coreToolsRelease.downloadLink ?: "")
Expand Down Expand Up @@ -156,6 +159,7 @@ class FunctionsToolingFeedService : Disposable {
if (!toolingReleasePath.exists())
toolingReleasePath.createDirectories()

LOG.trace { "Extracting from ${tempFile.absolutePath} to $toolingReleasePath" }
ZipUtil.extract(tempFile.toPath(), toolingReleasePath, null, true)

if (tempFile.exists())
Expand All @@ -166,8 +170,8 @@ class FunctionsToolingFeedService : Disposable {

return Result.success(toolingReleasePath)
} catch (e: Exception) {
toolingReleasePath.deleteRecursively()
LOG.warn("Unable to download Function core tools for the runtime version $azureFunctionsVersion")
toolingReleasePath.deleteRecursively()
return Result.failure(e)
}
}
Expand All @@ -182,35 +186,40 @@ class FunctionsToolingFeedService : Disposable {
}

private suspend fun getReleaseFeed(): ReleaseFeed {
val feedUrl = getReleaseFeedUrl()
val feedUrl = Registry.get("azure.function_app.core_tools.feed.url").asString()
LOG.trace { "Functions tooling release feed: $feedUrl" }

val response = withContext(Dispatchers.IO) {
client.get(feedUrl)
}

return response.body<ReleaseFeed>()
}

private fun getReleaseFeedUrl() = Registry.get("azure.function_app.core_tools.feed.url").asString()

private fun getLatestFunctionsToolingRelease(azureFunctionsVersion: String): FunctionsToolingRelease? {
val toolingRelease = releaseCache[azureFunctionsVersion.lowercase()]
if (toolingRelease == null) {
LOG.warn("Could not determine Azure Functions core tools release for version: '$azureFunctionsVersion'")
LOG.warn("Could not determine Functions tooling release for version: '$azureFunctionsVersion'")
return null
}

LOG.trace { "Latest Functions tooling release for version '$azureFunctionsVersion' is '$toolingRelease'" }

return toolingRelease
}

private fun getReleaseDownloadRoot(): Path? {
private fun getPathForLatestFunctionsToolingRelease(toolingRelease: FunctionsToolingRelease): Path? {
val settings = AzureFunctionSettings.getInstance()
val coreToolsDownloadFolder = settings.functionDownloadPath
return if (coreToolsDownloadFolder.isNotEmpty()) Path(coreToolsDownloadFolder)
else null
}
val downloadRoot =
if (coreToolsDownloadFolder.isNotEmpty()) Path(coreToolsDownloadFolder)
else null

private fun getPathForLatestFunctionsToolingRelease(toolingRelease: FunctionsToolingRelease): Path? {
val downloadRoot = getReleaseDownloadRoot()
return downloadRoot?.resolve(toolingRelease.functionsVersion)?.resolve(toolingRelease.releaseTag)
val path = downloadRoot?.resolve(toolingRelease.functionsVersion)?.resolve(toolingRelease.releaseTag)

LOG.trace { "Path for the Latest Functions tooling release is $path" }

return path
}

private fun Release.findCoreToolsRelease(releaseFilter: FunctionToolingFeedFilter) =
Expand All @@ -232,6 +241,7 @@ class FunctionsToolingFeedService : Disposable {
.firstOrNull()

private fun setExecutablePermissionsForCoreTools(coreToolsExecutable: Path) {
LOG.trace { "Setting permissions for $coreToolsExecutable" }
coreToolsExecutable.setPosixFilePermissions(
setOf(
PosixFilePermission.OWNER_EXECUTE,
Expand Down

0 comments on commit e65cdbb

Please sign in to comment.