-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #911 from atlanhq/DVX-671
Adds detailed search log entry option to adoption export
- Loading branch information
Showing
13 changed files
with
542 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...ckages/adoption-export/src/main/kotlin/com/atlan/pkg/adoption/exports/DetailedSearches.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 | ||
Copyright 2024 Atlan Pte. Ltd. */ | ||
package com.atlan.pkg.adoption.exports | ||
|
||
import com.atlan.model.search.SearchLogRequest | ||
import com.atlan.pkg.serde.xls.ExcelWriter | ||
import mu.KLogger | ||
|
||
class DetailedSearches( | ||
private val xlsx: ExcelWriter, | ||
private val logger: KLogger, | ||
private val start: Long, | ||
private val end: Long, | ||
) { | ||
fun export() { | ||
logger.info { "Exporting details of all UI-based searches between [$start, $end]..." } | ||
val sheet = xlsx.createSheet("User searches") | ||
xlsx.addHeader( | ||
sheet, | ||
mapOf( | ||
"Time" to "Time at which the search occurred", | ||
"Username" to "User who searched", | ||
"Query" to "Text the user entered for the search (if empty, the search was the result of filtering by some facet)", | ||
"Total" to "Total number of assets included", | ||
"Types" to "Type(s) of the first 20 assets that were found", | ||
"Qualified names" to "Unique name(s) of the first 20 assets that were found", | ||
), | ||
) | ||
SearchLogRequest.searches(start, end) | ||
.stream() | ||
.forEach { | ||
xlsx.appendRow( | ||
sheet, | ||
listOf( | ||
it.createdAt ?: it.timestamp ?: "", | ||
it.userName ?: "", | ||
it.searchInput ?: "", | ||
it.resultsCount ?: "0", | ||
it.resultTypeNamesAllowed ?: "", | ||
it.resultQualifiedNamesAllowed ?: "", | ||
), | ||
) | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...ges/adoption-export/src/main/kotlin/com/atlan/pkg/adoption/exports/DetailedUserChanges.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 | ||
Copyright 2024 Atlan Pte. Ltd. */ | ||
package com.atlan.pkg.adoption.exports | ||
|
||
import com.atlan.Atlan | ||
import com.atlan.model.enums.AuditActionType | ||
import com.atlan.model.search.AuditSearch | ||
import com.atlan.model.search.AuditSearchRequest | ||
import com.atlan.pkg.Utils | ||
import com.atlan.pkg.adoption.exports.AssetChanges.Companion.EXCLUDE_TYPES | ||
import com.atlan.pkg.serde.xls.ExcelWriter | ||
import mu.KLogger | ||
|
||
class DetailedUserChanges( | ||
private val xlsx: ExcelWriter, | ||
private val logger: KLogger, | ||
private val users: List<String>, | ||
private val actions: List<String>, | ||
private val start: Long, | ||
private val end: Long, | ||
private val includeAutomations: String, | ||
) { | ||
fun export() { | ||
logger.info { "Exporting details of all user-made changes between [$start, $end]..." } | ||
val sheet = xlsx.createSheet("User changes") | ||
xlsx.addHeader( | ||
sheet, | ||
mapOf( | ||
"Time" to "Time at which the change occurred", | ||
"Username" to "User who made the change", | ||
"Action" to "Type of change the user made", | ||
"Type" to "Type of asset", | ||
"Qualified name" to "Unique name of the asset", | ||
"Agent" to "Mechanism through which the asset was changed", | ||
"Details" to "Further details about the mechanism through which the asset was changed", | ||
"Link" to "Link to the asset's profile page in Atlan", | ||
), | ||
) | ||
val builder = | ||
AuditSearch.builder(Atlan.getDefaultClient()) | ||
.whereNot(AuditSearchRequest.ENTITY_TYPE.`in`(EXCLUDE_TYPES)) | ||
if (users.isNotEmpty()) { | ||
builder.where(AuditSearchRequest.USER.`in`(users)) | ||
} | ||
if (actions.isNotEmpty()) { | ||
builder.where(AuditSearchRequest.ACTION.`in`(actions)) | ||
} | ||
when (includeAutomations) { | ||
"NONE" -> builder.whereNot(AuditSearchRequest.AGENT.`in`(listOf("sdk", "workflow"))) | ||
"WFL" -> builder.whereNot(AuditSearchRequest.AGENT.eq("sdk")) | ||
"SDK" -> builder.whereNot(AuditSearchRequest.AGENT.eq("workflow")) | ||
else -> logger.info { " ... including ALL automations -- this could be a large amount of data (and take a LONG time)." } | ||
} | ||
if (start > 0) { | ||
builder.where(AuditSearchRequest.CREATED.gte(start)) | ||
} | ||
if (end > 0) { | ||
builder.where(AuditSearchRequest.CREATED.lt(end)) | ||
} | ||
builder.stream() | ||
.forEach { | ||
val agent = | ||
when (it.action) { | ||
AuditActionType.PROPAGATED_ATLAN_TAG_ADD, | ||
AuditActionType.PROPAGATED_ATLAN_TAG_UPDATE, | ||
AuditActionType.PROPAGATED_ATLAN_TAG_DELETE, | ||
-> "background" | ||
else -> it.headers?.get("x-atlan-agent") ?: "UI" | ||
} | ||
xlsx.appendRow( | ||
sheet, | ||
listOf( | ||
it.timestamp ?: "", | ||
it.user ?: "", | ||
it.action?.value ?: "", | ||
it.typeName ?: "", | ||
it.entityQualifiedName ?: "", | ||
agent, | ||
it.headers?.get("x-atlan-agent-id") ?: "", | ||
Utils.getAssetLink(it.entityId), | ||
), | ||
) | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...kages/adoption-export/src/main/kotlin/com/atlan/pkg/adoption/exports/DetailedUserViews.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 | ||
Copyright 2024 Atlan Pte. Ltd. */ | ||
package com.atlan.pkg.adoption.exports | ||
|
||
import com.atlan.model.search.SearchLogRequest | ||
import com.atlan.pkg.Utils | ||
import com.atlan.pkg.serde.xls.ExcelWriter | ||
import mu.KLogger | ||
|
||
class DetailedUserViews( | ||
private val xlsx: ExcelWriter, | ||
private val logger: KLogger, | ||
private val start: Long, | ||
private val end: Long, | ||
) { | ||
fun export() { | ||
logger.info { "Exporting details of all asset views between [$start, $end]..." } | ||
val sheet = xlsx.createSheet("User views") | ||
xlsx.addHeader( | ||
sheet, | ||
mapOf( | ||
"Time" to "Time at which the view / search occurred", | ||
"Username" to "User who viewed / searched", | ||
"Total" to "Total number of assets included", | ||
"Type" to "Type(s) of asset that were viewed", | ||
"Qualified name" to "Unique name(s) of the asset(s)", | ||
"Link" to "Link to the asset's profile page in Atlan", | ||
), | ||
) | ||
SearchLogRequest.views(start, end) | ||
.stream() | ||
.forEach { | ||
val guid = it.resultGuidsAllowed?.get(0) ?: "" | ||
xlsx.appendRow( | ||
sheet, | ||
listOf( | ||
it.createdAt ?: it.timestamp ?: "", | ||
it.userName ?: "", | ||
it.resultsCount ?: "0", | ||
it.resultTypeNamesAllowed ?: "", | ||
it.resultQualifiedNamesAllowed ?: "", | ||
if (guid.isNotBlank()) Utils.getAssetLink(guid) else "", | ||
), | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.