Skip to content

Commit 8744d71

Browse files
feat(cdn): merge main
2 parents 37ce7aa + 3055e05 commit 8744d71

42 files changed

Lines changed: 2599 additions & 249 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
## [0.28.2](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/compare/0.28.1...0.28.2) (2022-02-07)
2+
3+
4+
### Bug Fixes
5+
6+
* Fixed error with project connection ([058891f](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/058891fd6104de00103928a10b2473a46c68ff35))
7+
8+
## [0.28.1](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/compare/0.28.0...0.28.1) (2022-02-07)
9+
10+
11+
### Bug Fixes
12+
13+
* **bigQuery:** use API in dataset/table fetch ([bd8426d](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/bd8426d1769e5bf1635ab2da79eff94afed3ea14))
14+
15+
# [0.28.0](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/compare/0.27.0...0.28.0) (2022-02-07)
16+
17+
18+
### Features
19+
20+
* **dataproc:** add connection cluster to jobs ([5cf4683](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/5cf4683d629136028a9ac703cf882c8304ee83e3))
21+
* **dataproc:** add dataproc autoscaling policy ([d9e606c](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/d9e606c797c0fe1b0dda68f8e6c2b7c4a35da0d6))
22+
* **dataproc:** add dataproc cluster ([81a56c9](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/81a56c92d401f5cbd1573d1a748e764e6490394d))
23+
* **dataproc:** add dataproc job ([a50fe18](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/a50fe18d0c089ae4c0f0fe652d80acbe3bf892b3))
24+
* **dataproc:** add dataproc package ([83efe7c](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/83efe7c1c268a5ad2e4d1bc97a1c0a03abe50d90))
25+
* **dataproc:** add workflow template ([503b32f](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/503b32fde89433dfcbb305c53ae019ebad690c3e))
26+
* **dataproc:** couple updates/fixes to the cluster ([8461717](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/84617175fa3e3f5e40ac6622efa301e259088c92))
27+
* **dataproc:** update README ([5ea82a4](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/commit/5ea82a4b7876d7aa06b0a66f7bba5147d4246de4))
28+
129
# [0.27.0](https://gitlab.com/auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp/compare/0.26.0...0.27.0) (2022-02-03)
230

331

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ CloudGraph GCP Provider will ask you what regions you would like to crawl and wi
7676
| cloudFunction | project, vpc |
7777
| cloudRouter | project |
7878
| computeProject | project |
79+
| dataprocClusters | project, dataprocJobs, dataprocWorkflowTemplate |
80+
| dataprocAutoscalingPolicies | project |
81+
| dataprocJobs | project, dataprocClusters |
82+
| dataprocWorkflowTemplate | project, dataprocClusters |
7983
| kmsCryptoKeys | iamPolicy, kmsKeyRing, project |
8084
| dnsManagedZone | project |
8185
| dnsPolicy | project, network |

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudgraph/cg-provider-gcp",
3-
"version": "0.27.0",
3+
"version": "0.28.2",
44
"description": "CloudGraph provider plugin for GCP used to fetch GCP cloud data.",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org/",
@@ -34,16 +34,17 @@
3434
"dependencies": {
3535
"@cloudgraph/sdk": "^0.11.0",
3636
"@google-cloud/asset": "^3.22.0",
37+
"@google-cloud/bigquery": "^5.10.0",
38+
"@google-cloud/bigquery-connection": "^1.5.1",
39+
"@google-cloud/bigquery-data-transfer": "^2.3.0",
40+
"@google-cloud/bigquery-reservation": "^1.4.0",
3741
"@google-cloud/compute": "^3.0.0",
42+
"@google-cloud/dataproc": "^3.2.0",
3843
"@google-cloud/dns": "^2.2.3",
3944
"@google-cloud/functions": "^1.2.0",
4045
"@google-cloud/kms": "^2.10.0",
4146
"@google-cloud/logging": "^9.6.4",
4247
"@google-cloud/monitoring": "^2.3.5",
43-
"@google-cloud/bigquery": "^5.9.3",
44-
"@google-cloud/bigquery-connection": "^1.5.1",
45-
"@google-cloud/bigquery-data-transfer": "^2.3.0",
46-
"@google-cloud/bigquery-reservation": "^1.4.0",
4748
"@google-cloud/resource-manager": "^3.0.0",
4849
"@google-cloud/secret-manager": "^3.10.1",
4950
"@google-cloud/storage": "^5.16.1",

src/enums/schemasMap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ export default {
4343
[services.serviceAccount]: 'gcpServiceAccount',
4444
[services.apiKey]: 'gcpApiKey',
4545
[services.computeProject]: 'gcpComputeProject',
46+
[services.dataprocCluster]: 'gcpDataprocCluster',
47+
[services.dataprocAutoscalingPolicy]: 'gcpDataprocAutoscalingPolicy',
48+
[services.dataprocJob]: 'gcpDataprocJob',
49+
[services.dataprocWorkflowTemplate]: 'gcpDataprocWorkflowTemplate',
4650
tag: 'gcpTag',
4751
}

src/enums/serviceMap.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ import GcpSslPolicies from '../services/sslPolicy'
3939
import GcpServiceAccount from '../services/serviceAccount'
4040
import GcpApiKey from '../services/apiKey'
4141
import GcpComputeProject from '../services/computeProject'
42-
42+
import GcpDataprocCluster from '../services/dataprocCluster'
43+
import GcpDataprocAutoscalingPolicy from '../services/dataprocAutoscalingPolicy'
44+
import GcpDataprocJob from '../services/dataprocJob'
45+
import GcpDataprocWorkflowTemplate from '../services/dataprocWorkflowTemplate'
4346
/**
4447
* serviceMap is an object that contains all currently supported services
4548
* serviceMap is used by the serviceFactory to produce instances of service classes
@@ -84,5 +87,9 @@ export default {
8487
[services.serviceAccount]: GcpServiceAccount,
8588
[services.apiKey]: GcpApiKey,
8689
[services.computeProject]: GcpComputeProject,
90+
[services.dataprocCluster]: GcpDataprocCluster,
91+
[services.dataprocAutoscalingPolicy]: GcpDataprocAutoscalingPolicy,
92+
[services.dataprocJob]: GcpDataprocJob,
93+
[services.dataprocWorkflowTemplate]: GcpDataprocWorkflowTemplate,
8794
tag: GcpTag,
8895
}

src/enums/services.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export default {
3131
// composer: 'composer',
3232
// dataCatalog: 'data-catalog',
3333
// dataflow: 'dataflow',
34-
// dataproc: 'dataproc',
34+
dataprocCluster: 'dataprocClusters',
35+
dataprocAutoscalingPolicy: 'dataprocAutoscalingPolicies',
36+
dataprocJob: 'dataprocJobs',
37+
dataprocWorkflowTemplate: 'dataprocWorkflowTemplates',
3538
// metastore: 'metastore',
3639
// pubsub: 'pubsub',
3740
// bigtable: 'bigtable',

src/services/base/schema.graphql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ interface gcpBaseResource
1111
kind: String @search(by: [hash, regexp])
1212
labels: [gcpRawLabel]
1313
}
14+
15+
type gcpKeyValue
16+
@generate(
17+
query: { get: true, query: true, aggregate: true }
18+
mutation: { add: true, delete: false }
19+
subscription: false
20+
)
21+
@key(fields: "id") {
22+
id: String! @id @search(by: [hash])
23+
key: String! @search(by: [hash, regexp])
24+
value: String @search(by: [hash, regexp])
25+
}

src/services/bigQuery/data.ts

Lines changed: 70 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,86 @@
1-
import { BigQuery } from '@google-cloud/bigquery'
1+
import { DNS } from '@google-cloud/dns'
2+
import bigquery from '@google-cloud/bigquery/build/src/types'
23
import CloudGraph from '@cloudgraph/sdk'
34
import groupBy from 'lodash/groupBy'
5+
import isEmpty from 'lodash/isEmpty'
46
import gcpLoggerText from '../../properties/logger'
5-
import { GcpServiceInput } from '../../types'
7+
import { GcpCredentials, GcpServiceInput } from '../../types'
68
import { generateGcpErrorLog, initTestEndpoint } from '../../utils'
7-
import { RawGcpBigQueryDataset } from './types'
8-
import { MULTI_REGIONS } from '../../config/constants'
9+
import { listData } from '../../utils/fetchUtils'
910

1011
const lt = { ...gcpLoggerText }
1112
const { logger } = CloudGraph
1213
const serviceName = 'BigQuery Dataset'
1314
const apiEndpoint = initTestEndpoint(serviceName)
1415

15-
export default async ({
16-
regions,
17-
config,
18-
}: GcpServiceInput): Promise<{
19-
[region: string]: RawGcpBigQueryDataset[]
20-
}> => {
21-
const bigQueryClient = new BigQuery({ ...config, apiEndpoint })
22-
const datasetsResult: RawGcpBigQueryDataset[] = []
23-
const { projectId } = config
24-
const allRegions = regions.split(',').concat(MULTI_REGIONS)
25-
try {
26-
const dataSetIter = bigQueryClient.getDatasetsStream()
27-
for await (const dataSetResponse of dataSetIter) {
28-
if (allRegions.includes(dataSetResponse.location)) {
29-
const dsMetaData = dataSetResponse.metadata
30-
const result = {
31-
...dsMetaData,
32-
region: dataSetResponse.location,
33-
Labels: dataSetResponse.labels,
34-
tables: [],
35-
projectId,
36-
}
37-
try {
38-
const tableIter = dataSetResponse.getTablesStream()
39-
for await (const tableResponse of tableIter) {
40-
result.tables.push(tableResponse.metadata)
16+
export interface RawGcpBigQueryDataset extends bigquery.IDataset {
17+
projectId: string
18+
region: string
19+
tables: RawGcpBigQueryTable[]
20+
}
21+
22+
export interface RawGcpBigQueryTable extends bigquery.ITable {
23+
projectId: string
24+
region: string
25+
}
26+
27+
export const listBigQueryDatasets = async (
28+
config: GcpCredentials,
29+
datasetsResult: RawGcpBigQueryDataset[]
30+
): Promise<void> =>
31+
new Promise(async resolve => {
32+
const { projectId } = config
33+
34+
try {
35+
const service = new DNS({ ...config, apiEndpoint })
36+
const dataSetlist = await listData({
37+
service,
38+
apiUri: `https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets`,
39+
dataFieldName: 'datasets',
40+
})
41+
42+
for (const { datasetReference } of dataSetlist) {
43+
const dataSetResponse = await listData({
44+
service,
45+
apiUri: `https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetReference?.datasetId}`,
46+
})
47+
48+
if (!isEmpty(dataSetResponse)) {
49+
const result = {
50+
...dataSetResponse[0],
51+
region: dataSetResponse[0].location,
52+
tables: [],
53+
projectId,
54+
}
55+
56+
const tableResponse = await listData({
57+
service,
58+
apiUri: `https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetReference?.datasetId}/tables`,
59+
dataFieldName: 'tables',
60+
})
61+
62+
for (const table of tableResponse) {
63+
result.tables.push(table)
4164
}
4265
datasetsResult.push(result)
43-
} catch (error) {
44-
generateGcpErrorLog(serviceName, 'bigQuery:getTablesStream', error)
4566
}
4667
}
68+
} catch (error) {
69+
generateGcpErrorLog(serviceName, 'bigquery:datasets', error)
4770
}
48-
} catch (error) {
49-
generateGcpErrorLog(serviceName, 'bigQuery:getDatasetsStream', error)
50-
}
71+
resolve()
72+
})
5173

52-
logger.debug(lt.foundResources(serviceName, datasetsResult.length))
53-
return groupBy(datasetsResult, 'region')
54-
}
74+
export default async ({
75+
config,
76+
}: GcpServiceInput): Promise<{
77+
[region: string]: RawGcpBigQueryDataset[]
78+
}> =>
79+
new Promise(async resolve => {
80+
const datasetsResult: RawGcpBigQueryDataset[] = []
81+
82+
await listBigQueryDatasets(config, datasetsResult)
83+
84+
logger.debug(lt.foundResources(serviceName, datasetsResult.length))
85+
resolve(groupBy(datasetsResult, 'region'))
86+
})

src/services/bigQuery/format.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
GcpBigQueryTableViewUserDefinedFunctionResource,
88
} from '../../types/generated'
99
import { formatLabelsFromMap } from '../../utils/format'
10-
import { RawGcpBigQueryDataset, RawGcpBigQueryTable } from './types'
10+
import { toISOString, millisToSeconds } from '../../utils/dateutils'
11+
import { RawGcpBigQueryDataset, RawGcpBigQueryTable } from './data'
1112

1213
const formatTableField = (field): GcpBigQueryTableSchemaField => {
1314
const {
@@ -134,9 +135,9 @@ const formatTable = (table: RawGcpBigQueryTable): GcpBigQueryTable => {
134135
numBytes,
135136
numLongTermBytes,
136137
numRows,
137-
creationTime,
138-
expirationTime,
139-
lastModifiedTime,
138+
creationTime: toISOString(millisToSeconds(creationTime)),
139+
expirationTime: toISOString(millisToSeconds(expirationTime)),
140+
lastModifiedTime: toISOString(millisToSeconds(lastModifiedTime)),
140141
viewQuery: view?.query || '',
141142
viewUserDefinedFunctionResources: view?.userDefinedFunctionResources?.map(
142143
resource => formatTableViewUserDefinedFunctionResource(resource)
@@ -173,7 +174,6 @@ const formatTable = (table: RawGcpBigQueryTable): GcpBigQueryTable => {
173174
externalDataConfiguration?.hivePartitioningOptions?.sourceUriPrefix || '',
174175
externalDataConfigurationHivePartitioningOptionsRequirePartitionFilter:
175176
externalDataConfiguration?.hivePartitioningOptions?.requirePartitionFilter || false,
176-
externalDataConfigurationHivePartitioningOptionsFields: externalDataConfiguration?.hivePartitioningOptions?.fields || [],
177177
externalDataConfigurationConnectionId: externalDataConfiguration?.connectionId || '',
178178
externalDataConfigurationDecimalTargetTypes: externalDataConfiguration?.decimalTargetTypes || [],
179179
externalDataConfigurationAvroOptionsUseAvroLogicalTypes:externalDataConfiguration?.avroOptions?.useAvroLogicalTypes || false,
@@ -201,18 +201,47 @@ export default ({
201201
}): GcpBigQueryDataset => {
202202
const {
203203
id,
204+
projectId,
204205
kind,
206+
labels = {},
207+
etag,
208+
selfLink,
209+
datasetReference,
210+
friendlyName,
211+
description,
212+
defaultTableExpirationMs,
213+
defaultPartitionExpirationMs,
214+
access,
215+
creationTime,
216+
lastModifiedTime,
217+
location,
218+
defaultEncryptionConfiguration,
219+
satisfiesPZS,
205220
tables = [],
206-
labels = {}
207221
} = service
208222

209223
return {
210224
id: id || cuid(),
211-
projectId: account,
225+
projectId,
212226
region,
213227
kind,
214228
labels: formatLabelsFromMap(labels),
215-
totalTables: tables.length || 0,
229+
etag,
230+
selfLink,
231+
datasetReference,
232+
friendlyName,
233+
description,
234+
defaultTableExpirationMs,
235+
defaultPartitionExpirationMs,
236+
access: access?.map(acc => ({
237+
id: cuid(),
238+
...acc,
239+
})),
240+
creationTime: toISOString(millisToSeconds(creationTime)),
241+
lastModifiedTime: toISOString(millisToSeconds(lastModifiedTime)),
242+
location,
243+
defaultEncryptionConfiguration,
244+
satisfiesPzs: satisfiesPZS,
216245
tables: tables.map(table => formatTable(table)) || []
217246
}
218247
}

src/services/bigQuery/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import getData from './data'
55
import mutation from './mutation'
66

77
export default class GcpBigQuery extends BaseService implements Service {
8-
format = format.bind(this)
8+
format = format.bind(this)
99

1010
getData = getData.bind(this)
1111

0 commit comments

Comments
 (0)