Skip to content

Commit

Permalink
Change logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
CamaradeRoman committed May 24, 2024
1 parent b99b31d commit 26bacca
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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
Expand All @@ -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()

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
}

Expand All @@ -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(
Expand All @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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(
Expand All @@ -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() }

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 26bacca

Please sign in to comment.