Skip to content

Commit 0bea6e7

Browse files
authored
feat: Pass installation ID from env to usage report (#2106)
Goes with cloudquery/cloudquery#20455
1 parent 9c8ab01 commit 0bea6e7

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

examples/simple_plugin/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/bahlo/generic-list-go v0.2.0 // indirect
3333
github.com/buger/jsonparser v1.1.1 // indirect
3434
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
35-
github.com/cloudquery/cloudquery-api-go v1.13.7 // indirect
35+
github.com/cloudquery/cloudquery-api-go v1.13.8 // indirect
3636
github.com/cloudquery/plugin-pb-go v1.26.8 // indirect
3737
github.com/cloudquery/plugin-sdk/v2 v2.7.0 // indirect
3838
github.com/davecgh/go-spew v1.1.1 // indirect

examples/simple_plugin/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMU
5050
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
5151
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
5252
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
53-
github.com/cloudquery/cloudquery-api-go v1.13.7 h1:XWn9TVLpKswTrNQT9MY/HUiQWwhyoMWKpGWoRcQM5bE=
54-
github.com/cloudquery/cloudquery-api-go v1.13.7/go.mod h1:ZhEjPkDGDL2KZKlQLUnsgQ0mPz3qC7qftr37q3q+IcA=
53+
github.com/cloudquery/cloudquery-api-go v1.13.8 h1:8n5D0G2wynbUdexr1GS8ND8i0uOwm0gXKNipJsijPe0=
54+
github.com/cloudquery/cloudquery-api-go v1.13.8/go.mod h1:ZhEjPkDGDL2KZKlQLUnsgQ0mPz3qC7qftr37q3q+IcA=
5555
github.com/cloudquery/plugin-pb-go v1.26.8 h1:mHNyOyG/MW/rjDVR0OR8DdezXmyoD4drphyHlYmnJoY=
5656
github.com/cloudquery/plugin-pb-go v1.26.8/go.mod h1:orruK+wdIP3kOvmEQhCcFND2bVVH7o0fFSGrqZYMt7k=
5757
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/aws/aws-sdk-go-v2/service/licensemanager v1.30.1
1212
github.com/aws/aws-sdk-go-v2/service/marketplacemetering v1.26.2
1313
github.com/bradleyjkemp/cupaloy/v2 v2.8.0
14-
github.com/cloudquery/cloudquery-api-go v1.13.7
14+
github.com/cloudquery/cloudquery-api-go v1.13.8
1515
github.com/cloudquery/plugin-pb-go v1.26.8
1616
github.com/cloudquery/plugin-sdk/v2 v2.7.0
1717
github.com/goccy/go-json v0.10.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMU
5050
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
5151
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
5252
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
53-
github.com/cloudquery/cloudquery-api-go v1.13.7 h1:XWn9TVLpKswTrNQT9MY/HUiQWwhyoMWKpGWoRcQM5bE=
54-
github.com/cloudquery/cloudquery-api-go v1.13.7/go.mod h1:ZhEjPkDGDL2KZKlQLUnsgQ0mPz3qC7qftr37q3q+IcA=
53+
github.com/cloudquery/cloudquery-api-go v1.13.8 h1:8n5D0G2wynbUdexr1GS8ND8i0uOwm0gXKNipJsijPe0=
54+
github.com/cloudquery/cloudquery-api-go v1.13.8/go.mod h1:ZhEjPkDGDL2KZKlQLUnsgQ0mPz3qC7qftr37q3q+IcA=
5555
github.com/cloudquery/plugin-pb-go v1.26.8 h1:mHNyOyG/MW/rjDVR0OR8DdezXmyoD4drphyHlYmnJoY=
5656
github.com/cloudquery/plugin-pb-go v1.26.8/go.mod h1:orruK+wdIP3kOvmEQhCcFND2bVVH7o0fFSGrqZYMt7k=
5757
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=

premium/usage.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,9 @@ type BatchUpdater struct {
180180
awsMarketplaceClient AWSMarketplaceClientInterface
181181

182182
// Plugin details
183-
teamName cqapi.TeamName
184-
pluginMeta plugin.Meta
183+
teamName cqapi.TeamName
184+
pluginMeta plugin.Meta
185+
installationID string
185186

186187
// Configuration
187188
batchLimit uint32
@@ -284,6 +285,7 @@ func NewUsageClient(meta plugin.Meta, ops ...UsageClientOptions) (UsageClient, e
284285
}
285286
u.teamName = teamName
286287
}
288+
u.installationID = determineInstallationID(u.tokenClient.GetTokenType())
287289

288290
u.backgroundUpdater()
289291

@@ -634,7 +636,9 @@ func (u *BatchUpdater) updateUsageWithRetryAndBackoff(ctx context.Context, rows
634636
PluginName: u.pluginMeta.Name,
635637
Rows: int(rows),
636638
}
637-
639+
if len(u.installationID) > 0 {
640+
payload.InstallationID = &u.installationID
641+
}
638642
if len(tables) > 0 {
639643
payload.Tables = &tables
640644
}
@@ -724,6 +728,15 @@ func (u *BatchUpdater) getTeamNameByTokenType(tokenType auth.TokenType) (string,
724728
}
725729
}
726730

731+
func determineInstallationID(tokenType auth.TokenType) string {
732+
switch tokenType {
733+
case auth.SyncRunAPIKey, auth.SyncTestConnectionAPIKey:
734+
return os.Getenv("_CQ_INSTALLATION_ID")
735+
default:
736+
return ""
737+
}
738+
}
739+
727740
type NoOpUsageClient struct {
728741
TeamNameValue string
729742
}

0 commit comments

Comments
 (0)