From 26baccaa1c3d832c0b66b51e88c0a669fb4dd9c1 Mon Sep 17 00:00:00 2001 From: Roman Ivanov Date: Fri, 24 May 2024 14:37:20 +0300 Subject: [PATCH] Change logging. --- .../controller/GiteaIndexerController.kt | 8 ++--- .../controller/RepositoryController.kt | 14 ++++----- .../controller/RepositoryControllerOld.kt | 10 +++---- .../controller/RepositoryControllerV1.kt | 10 +++---- .../service/impl/GiteaIndexerServiceImpl.kt | 30 +++++++++---------- .../vcsfacade/service/impl/VcsManagerImpl.kt | 6 ++-- 6 files changed, 39 insertions(+), 39 deletions(-) diff --git a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/GiteaIndexerController.kt b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/GiteaIndexerController.kt index 13ec47b..f82e2da 100644 --- a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/GiteaIndexerController.kt +++ b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/GiteaIndexerController.kt @@ -66,7 +66,7 @@ class GiteaIndexerController( if (eventType == "create" && event == "create") { with(objectMapper.readValue(payload, GiteaCreateRefEvent::class.java)) { log.info( - "Register `{}` {} creation in `{}` {} repository", + "Register '{}' {} creation in {} {} repository", ref, refType.jsonValue, repository.fullName, @@ -77,7 +77,7 @@ class GiteaIndexerController( } else if (eventType == "delete" && event == "delete") { with(objectMapper.readValue(payload, GiteaDeleteRefEvent::class.java)) { log.info( - "Register `{}` {} deletion in `{}` {} repository", + "Register '{}' {} deletion in {} {} repository", ref, refType.jsonValue, repository.fullName, @@ -87,12 +87,12 @@ class GiteaIndexerController( } } else if (eventType == "push" && event == "push") { with(objectMapper.readValue(payload, GiteaPushEvent::class.java)) { - log.info("Register {} commit(s) in `{}` {} repository", commits.size, repository.fullName, GITEA) + log.info("Register {} commit(s) in {} {} repository", commits.size, repository.fullName, GITEA) giteaIndexerService.registerGiteaPushEvent(this) } } else if (eventType == "pull_request" && event == "pull_request") { with(objectMapper.readValue(payload, GiteaPullRequestEvent::class.java)) { - log.info("Register {} pull request in `{}` {} repository", action, repository.fullName, GITEA) + log.info("Register {} pull request in {} {} repository", action, repository.fullName, GITEA) giteaIndexerService.registerGiteaPullRequestEvent(this) } } diff --git a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryController.kt b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryController.kt index 26bdfcb..eb3e845 100644 --- a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryController.kt +++ b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryController.kt @@ -51,7 +51,7 @@ class RepositoryController( @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processRequest(requestId ?: UUID.randomUUID().toString()) { log.info( - "Get commits ({},{}] in `{}` repository", + "Get commits ({},{}] in {} repository", (fromHashOrRef ?: fromDate?.toString()).orEmpty(), toHashOrRef, sshUrl @@ -69,7 +69,7 @@ class RepositoryController( @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processRequest(requestId ?: UUID.randomUUID().toString()) { log.info( - "Get commits ({},{}] with files (limit {}) in `{}` repository", + "Get commits ({},{}] with files (limit {}) in {} repository", (fromHashOrRef ?: fromDate?.toString()).orEmpty(), toHashOrRef, commitFilesLimit, @@ -87,7 +87,7 @@ class RepositoryController( @RequestParam("hashOrRef") hashOrRef: String, @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processRequest(requestId ?: UUID.randomUUID().toString()) { - log.info("Get commit {} in `{}` repository", hashOrRef, sshUrl) + log.info("Get commit {} in {} repository", hashOrRef, sshUrl) vcsManager.getCommit(sshUrl, hashOrRef) } @@ -98,7 +98,7 @@ class RepositoryController( @RequestParam("commitFilesLimit", defaultValue = "0") commitFilesLimit: Int, @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processRequest(requestId ?: UUID.randomUUID().toString()) { - log.info("Get commit {} with files (limit {}) in `{}` repository", hashOrRef, commitFilesLimit, sshUrl) + log.info("Get commit {} with files (limit {}) in {} repository", hashOrRef, commitFilesLimit, sshUrl) vcsManager.getCommitWithFiles(sshUrl, hashOrRef).applyCommitFilesLimit(commitFilesLimit) } @@ -111,7 +111,7 @@ class RepositoryController( @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processRequest(requestId ?: UUID.randomUUID().toString()) { log.info( - "Find issue keys in commits ({},{}] in `{}` repository", + "Find issue keys in commits ({},{}] in {} repository", (fromHashOrRef ?: fromDate?.toString()).orEmpty(), toHashOrRef, sshUrl @@ -128,7 +128,7 @@ class RepositoryController( @RequestParam("sshUrl") sshUrl: String, @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processRequest(requestId ?: UUID.randomUUID().toString()) { - log.info("Get tags in `{}` repository", sshUrl) + log.info("Get tags in {} repository", sshUrl) RepositoryResponse(vcsManager.getTags(sshUrl)) }.data.sorted() @@ -151,7 +151,7 @@ class RepositoryController( @RequestBody createPullRequest: CreatePullRequest ): PullRequest { log.info( - "Create pull request ({} -> {}) in `{}` repository", + "Create pull request ({} -> {}) in {} repository", sshUrl, createPullRequest.sourceBranch, createPullRequest.targetBranch diff --git a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryControllerOld.kt b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryControllerOld.kt index ab925f3..f7566ee 100644 --- a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryControllerOld.kt +++ b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryControllerOld.kt @@ -58,7 +58,7 @@ class RepositoryControllerOld( @RequestParam("fromDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) fromDate: Date?, @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processJob(requestId ?: UUID.randomUUID().toString()) { - log.info("Get commits ({},{}] in `{}` repository", (from ?: fromDate?.toString()).orEmpty(), to, vcsPath) + log.info("Get commits ({},{}] in {} repository", (from ?: fromDate?.toString()).orEmpty(), to, vcsPath) RepositoryResponse(vcsManager.getCommits(vcsPath, from, fromDate, to).map { it.toOld() }) }.data @@ -83,7 +83,7 @@ class RepositoryControllerOld( @RequestParam("vcsPath") vcsPath: String, @RequestParam("commitId") commitIdOrRef: String ): CommitOld { - log.info("Get commit {} in `{}` repository", commitIdOrRef, vcsPath) + log.info("Get commit {} in {} repository", commitIdOrRef, vcsPath) return vcsManager.getCommit(vcsPath, commitIdOrRef).toOld() } @@ -96,7 +96,7 @@ class RepositoryControllerOld( @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processJob(requestId ?: UUID.randomUUID().toString()) { log.info( - "Find issue keys in commits ({},{}] in `{}` repository", + "Find issue keys in commits ({},{}] in {} repository", (from ?: fromDate?.toString()).orEmpty(), to, vcsPath ) RepositoryResponse( @@ -120,7 +120,7 @@ class RepositoryControllerOld( @RequestParam("vcsPath") vcsPath: String, @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processJob(requestId ?: UUID.randomUUID().toString()) { - log.info("Get tags in `{}` repository", vcsPath) + log.info("Get tags in {} repository", vcsPath) RepositoryResponse(vcsManager.getTags(vcsPath).map { it.toOld() }) }.data @@ -144,7 +144,7 @@ class RepositoryControllerOld( @RequestBody createPullRequest: CreatePullRequest ): PullRequestResponse { log.info( - "Create pull request ({} -> {}) in `{}` repository", + "Create pull request ({} -> {}) in {} repository", vcsPath, createPullRequest.sourceBranch, createPullRequest.targetBranch diff --git a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryControllerV1.kt b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryControllerV1.kt index 404b21f..fa7d0d8 100644 --- a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryControllerV1.kt +++ b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/controller/RepositoryControllerV1.kt @@ -58,13 +58,13 @@ class RepositoryControllerV1( @RequestParam("fromDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) fromDate: Date?, @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processRequest(requestId ?: UUID.randomUUID().toString()) { - log.info("Get commits ({},{}] in `{}` repository", (from ?: fromDate?.toString()).orEmpty(), to, sshUrl) + log.info("Get commits ({},{}] in {} repository", (from ?: fromDate?.toString()).orEmpty(), to, sshUrl) RepositoryResponse(vcsManager.getCommits(sshUrl, from, fromDate, to)) }.data.sorted().map { it.toV1() } @GetMapping("commit", produces = [MediaType.APPLICATION_JSON_VALUE]) fun getCommit(@RequestParam("sshUrl") sshUrl: String, @RequestParam("commitId") commitId: String): CommitV1 { - log.info("Get commit {} in `{}` repository", commitId, sshUrl) + log.info("Get commit {} in {} repository", commitId, sshUrl) return vcsManager.getCommit(sshUrl, commitId).toV1() } @@ -77,7 +77,7 @@ class RepositoryControllerV1( @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processRequest(requestId ?: UUID.randomUUID().toString()) { log.info( - "Find issue keys in commits ({},{}] in `{}` repository", + "Find issue keys in commits ({},{}] in {} repository", (from ?: fromDate?.toString()).orEmpty(), to, sshUrl ) RepositoryResponse( @@ -92,7 +92,7 @@ class RepositoryControllerV1( @RequestParam("sshUrl") sshUrl: String, @RequestHeader(Constants.DEFERRED_RESULT_HEADER, required = false) requestId: String? ) = processRequest(requestId ?: UUID.randomUUID().toString()) { - log.info("Get tags in `{}` repository", sshUrl) + log.info("Get tags in {} repository", sshUrl) RepositoryResponse(vcsManager.getTags(sshUrl)) }.data.sorted().map { it.toV1() } @@ -114,7 +114,7 @@ class RepositoryControllerV1( @RequestParam("sshUrl") sshUrl: String, @RequestBody createPullRequest: CreatePullRequest ): PullRequest { log.info( - "Create pull request ({} -> {}) in `{}` repository", + "Create pull request ({} -> {}) in {} repository", sshUrl, createPullRequest.sourceBranch, createPullRequest.targetBranch diff --git a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/service/impl/GiteaIndexerServiceImpl.kt b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/service/impl/GiteaIndexerServiceImpl.kt index 695cefd..8ec30ab 100644 --- a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/service/impl/GiteaIndexerServiceImpl.kt +++ b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/service/impl/GiteaIndexerServiceImpl.kt @@ -119,7 +119,7 @@ class GiteaIndexerServiceImpl( private fun Repository.toRepositoryDocument(): RepositoryDocument { if (!giteaService.isSupport(sshUrl)) { - throw IllegalStateException("`$sshUrl` is not supported $GITEA repository") + throw IllegalStateException("$sshUrl is not supported $GITEA repository") } val (group, name) = giteaService.parse(sshUrl) return RepositoryDocument(GITEA, group, name, sshUrl, link, avatar) @@ -179,7 +179,7 @@ class GiteaIndexerServiceImpl( private fun scan(repositoryDocument: RepositoryDocument) = try { giteaService.findRepository(repositoryDocument.group, repositoryDocument.name)?.let { foundRepository -> with(RepositoryInfoDocument(foundRepository.toRepositoryDocument(), false, Date())) { - log.debug("Save repository info in index for `{}` {} repository", repository.fullName(), GITEA) + log.debug("Save repository info in index for {} {} repository", repository.fullName(), GITEA) openSearchService.saveRepositoriesInfo(sequenceOf(this)) val branches = giteaService.getBranches(repository.group, repository.name).map { it.toDocument(repository) @@ -190,16 +190,16 @@ class GiteaIndexerServiceImpl( val orphanedRefsIds = (openSearchService.findRefsIdsByRepositoryId(repository.id) - (branches.map { it.id } + tags.map { it.id }).toSet()).asSequence() logIndexActionMessage( - "Remove orphaned refs from index for `${repository.fullName()}` $GITEA repository", + "Remove orphaned refs from index for ${repository.fullName()} $GITEA repository", orphanedRefsIds ) openSearchService.deleteRefsByIds(orphanedRefsIds) logIndexActionMessage( - "Save branches in index for `${repository.fullName()}` $GITEA repository", branches + "Save branches in index for ${repository.fullName()} $GITEA repository", branches ) openSearchService.saveRefs(branches) logIndexActionMessage( - "Save tags in index for `${repository.fullName()}` $GITEA repository", tags + "Save tags in index for ${repository.fullName()} $GITEA repository", tags ) openSearchService.saveRefs(tags) val commits = giteaService.getBranchesCommitGraph(repository.group, repository.name).map { @@ -208,12 +208,12 @@ class GiteaIndexerServiceImpl( val orphanedCommitsIds = (openSearchService.findCommitsIdsByRepositoryId(repository.id) - commits.map { it.id }.toSet()).asSequence() logIndexActionMessage( - "Remove orphaned commits from index for `${repository.fullName()}` $GITEA repository", + "Remove orphaned commits from index for ${repository.fullName()} $GITEA repository", orphanedCommitsIds ) openSearchService.deleteCommitsByIds(orphanedCommitsIds) logIndexActionMessage( - "Save commits in index for `${repository.fullName()}` $GITEA repository ", commits + "Save commits in index for ${repository.fullName()} $GITEA repository ", commits ) openSearchService.saveCommits(commits) val pullRequests = try { @@ -224,28 +224,28 @@ class GiteaIndexerServiceImpl( val orphanedPullRequestsIds = (openSearchService.findPullRequestsIdsByRepositoryId(repository.id) - pullRequests.map { it.id }.toSet()).asSequence() logIndexActionMessage( - "Remove orphaned pull requests from index for `${repository.fullName()}` $GITEA repository", + "Remove orphaned pull requests from index for ${repository.fullName()} $GITEA repository", orphanedPullRequestsIds ) openSearchService.deletePullRequestsByIds(orphanedPullRequestsIds) logIndexActionMessage( - "Save pull requests in index for `${repository.fullName()}` $GITEA repository ", pullRequests + "Save pull requests in index for ${repository.fullName()} $GITEA repository ", pullRequests ) openSearchService.savePullRequests(pullRequests) } } ?: run { - log.debug("Remove `{}` {} repository pull-requests from index", repositoryDocument.fullName(), GITEA) + log.debug("Remove {} {} repository pull-requests from index", repositoryDocument.fullName(), GITEA) openSearchService.deletePullRequestsByRepositoryId(repositoryDocument.id) - log.debug("Remove `{}` {} repository commits from index", repositoryDocument.fullName(), GITEA) + log.debug("Remove {} {} repository commits from index", repositoryDocument.fullName(), GITEA) openSearchService.deleteCommitsByRepositoryId(repositoryDocument.id) - log.debug("Remove `{}` {} repository refs from index", repositoryDocument.fullName(), GITEA) + log.debug("Remove {} {} repository refs from index", repositoryDocument.fullName(), GITEA) openSearchService.deleteRefsByRepositoryId(repositoryDocument.id) - log.debug("Remove repository info from index for `{}` {} repository", repositoryDocument.fullName(), GITEA) + log.debug("Remove repository info from index for {} {} repository", repositoryDocument.fullName(), GITEA) openSearchService.deleteRepositoryInfoById(repositoryDocument.id) } - log.info("Scanning of `{}` {} repository completed successfully", repositoryDocument.fullName(), GITEA) + log.info("Scanning of {} {} repository completed successfully", repositoryDocument.fullName(), GITEA) } catch (e: Exception) { - log.error("Scanning of `${repositoryDocument.fullName()}` $GITEA repository ended in failure", e) + log.error("Scanning of ${repositoryDocument.fullName()} $GITEA repository ended in failure", e) openSearchService.saveRepositoriesInfo(sequenceOf(RepositoryInfoDocument(repositoryDocument))) } diff --git a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/service/impl/VcsManagerImpl.kt b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/service/impl/VcsManagerImpl.kt index 1aea510..7172fe7 100644 --- a/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/service/impl/VcsManagerImpl.kt +++ b/server/src/main/kotlin/org/octopusden/octopus/vcsfacade/service/impl/VcsManagerImpl.kt @@ -189,12 +189,12 @@ class VcsManagerImpl( val expectedCommits = it.healthCheck.expectedCommits if (expectedCommits != commits) { val diff = (commits - expectedCommits).union(expectedCommits - commits) - "The symmetric difference of response commits with expected commits is $diff, repository `${it.healthCheck.repo}`".also { message -> + "The symmetric difference of response commits with expected commits is $diff, repository ${it.healthCheck.repo}".also { message -> log.warn(message) } } else null } catch (e: Exception) { - "Health check request to repository `${it.healthCheck.repo}` ended with exception".also { message -> + "Health check request to repository ${it.healthCheck.repo} ended with exception".also { message -> log.warn(message, e) } } @@ -209,7 +209,7 @@ class VcsManagerImpl( } private fun getVcsService(sshUrl: String) = vcsServices.firstOrNull { it.isSupport(sshUrl) } - ?: throw IllegalStateException("There is no configured VCS service for `$sshUrl`") + ?: throw IllegalStateException("There is no configured VCS service for $sshUrl") companion object { private val log = LoggerFactory.getLogger(VcsManagerImpl::class.java)