Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f157c53
add authScopes to emitUserState telemetry
samgst-amazon Oct 7, 2024
f0d455d
add authScopes to emitUserState telemetry
samgst-amazon Oct 7, 2024
924a2b0
Replace userState function with direct TelemetryService record functi…
samgst-amazon Oct 7, 2024
4512625
add value parameter
samgst-amazon Oct 7, 2024
a4db555
fix whitespace
samgst-amazon Oct 7, 2024
4e1af21
Update plugins/core/jetbrains-community/src/software/aws/toolkits/jet…
samgst-amazon Oct 8, 2024
df30b58
Check current explorerConnection for scopes only
samgst-amazon Oct 15, 2024
2d053c5
Add function to grab scopes from each activeConnection used that is c…
samgst-amazon Oct 16, 2024
13c8cd0
remove TelemetryOverride definition and use common's telemetry functi…
samgst-amazon Oct 18, 2024
d05315f
remove unused imports
samgst-amazon Oct 18, 2024
744a2d3
Change the way explorer connection scope is checked
samgst-amazon Oct 18, 2024
098fa1d
remove check for CodeWhispererConnection: merged into qConnection & q…
samgst-amazon Oct 21, 2024
e6082fe
add common logic to one function
samgst-amazon Nov 1, 2024
214f4d8
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 4, 2024
e3e4838
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 4, 2024
5f780a1
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 5, 2024
1404bb1
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 6, 2024
82708b7
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 7, 2024
3ade8d8
Update telemetryOverride.json
samgst-amazon Nov 7, 2024
0858d1b
Merge branch 'main' into samgst/emitAuthScopesInUserState
samgst-amazon Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package software.aws.toolkits.jetbrains.core.gettingstarted

import com.intellij.openapi.project.Project
import software.aws.toolkits.jetbrains.services.telemetry.TelemetryService
import software.amazon.awssdk.services.toolkittelemetry.model.Unit
import software.aws.toolkits.core.utils.tryOrNull
import software.aws.toolkits.jetbrains.core.credentials.LegacyManagedBearerSsoConnection
import software.aws.toolkits.jetbrains.core.credentials.ManagedBearerSsoConnection
Expand All @@ -15,6 +17,7 @@ import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection
import software.aws.toolkits.jetbrains.core.credentials.reauthConnectionIfNeeded
import software.aws.toolkits.jetbrains.core.credentials.sono.Q_SCOPES
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.SourceOfEntry
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.getAuthScopes
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.getAuthStatus
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.getConnectionCount
import software.aws.toolkits.jetbrains.core.gettingstarted.editor.getEnabledConnections
Expand All @@ -26,6 +29,7 @@ import software.aws.toolkits.resources.AwsCoreBundle
import software.aws.toolkits.telemetry.AuthTelemetry
import software.aws.toolkits.telemetry.FeatureId
import software.aws.toolkits.telemetry.Result
import java.time.Instant

fun requestCredentialsForCodeWhisperer(
project: Project,
Expand Down Expand Up @@ -229,13 +233,19 @@ fun reauthenticateWithQ(project: Project) {
}

fun emitUserState(project: Project) {
AuthTelemetry.userState(
project,
source = getStartupState().toString(),
authEnabledConnections = getEnabledConnections(project),
authStatus = getAuthStatus(project),
passive = true
)

TelemetryService.getInstance().record(project) {
datum("auth_userState") {
createTime(Instant.now())
unit(Unit.NONE)
value(1.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are implicit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are implicit if you use the userState function in AuthTelemetry-- which just calls the TelemetryService function using these values. I thought I had to add them here since I was not using the userState function and they weren't being set. I did not see a method signature in AuthTelemetry that would let me pass in the extra authScopes datum-- and I wasn't sure where/if I could update the userState method.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This metric is currently in telemetryOverride. We need to use the one from common.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that our AuthTelemetry is being generated. no version of AuthTelemetry.userState() accepts authScopes as a parameter. I think this might be why? :

https://github.com/aws/aws-toolkit-common/blob/49de773b65efdeaadea5c30859cf286ccd74ec5b/telemetry/definitions/commonDefinitions.json#L2708C1-L2710C19

I'll try making some changes to common locally to see if I can generate a version of the function that does.

passive(true)
metadata("source", getStartupState().toString())
metadata("authStatus", getAuthStatus(project).toString())
metadata("authEnabledConnections", getEnabledConnections(project))
metadata("authScopes", getAuthScopes(project))
}
}
}

const val CODEWHISPERER_AUTH_LEARN_MORE_LINK = "https://docs.aws.amazon.com/codewhisperer/latest/userguide/codewhisperer-auth.html"
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,37 @@ fun getEnabledConnectionsForTelemetry(project: Project?): Set<AuthFormId> {
fun getEnabledConnections(project: Project?): String =
getEnabledConnectionsForTelemetry(project).joinToString(",")

fun getAuthScopesForTelemetry(project: Project?): Set<String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function above repeats some of the logic used here, can we move the common logic to a function?

project ?: return emptySet()
val scopes = mutableSetOf<String>()

fun addScopes(connection: ActiveConnection) {
if (connection !is ActiveConnection.NotConnected) {
val connectionScopes = connection.activeConnectionBearer?.scopes
if (connectionScopes != null) {
scopes.addAll(connectionScopes)
}
}
}

val explorerConnection = checkIamConnectionValidity(project)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also probably check the connection type and use the addScopes function only if the connection type is IDC. We can probably just hardcode it anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the connection type of the explorer only? Would that not ignore the other connections/scopes available if those other features are using the IdC connection type while the explorer isnt?

addScopes(explorerConnection)

val codeCatalystConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet.CODECATALYST)
addScopes(codeCatalystConnection)

val codeWhispererConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet.CODEWHISPERER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we still need this since Q or we should just record Q

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Dhruvi: " let's not be concerned about old customers since most of them have migrated"

I'll remove it.

addScopes(codeWhispererConnection)

val qConnection = checkBearerConnectionValidity(project, BearerTokenFeatureSet.Q)
addScopes(qConnection)

return scopes
}

fun getAuthScopes(project: Project?): String =
getAuthScopesForTelemetry(project).joinToString(",")

fun getStartupState(): StartUpState {
val hasStartedToolkitBefore = tryOrNull {
getPersistentStateComponentStorageLocation(AwsSettings::class.java)?.exists()
Expand Down
Loading