Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit e208722

Browse files
authored
Merge branch 'master' into inspect_classify
2 parents 8b59468 + 1d32b05 commit e208722

19 files changed

Lines changed: 402 additions & 51 deletions

.github/workflows/dlp-pipelines.yml

Lines changed: 254 additions & 4 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ To run the pipeline for JSONL files, the list of comma-separated headers also ne
506506
./gradlew run ... -Pargs="... --filePattern=gs://${PROJECT_ID}-demo-data/CCRecords_sample.jsonl --headers=<comma_separated_list_of_headers>"
507507
```
508508

509+
The original schema of the input file will not be preserved. This solution simplifies the data when it converts the data
510+
to a DLP API request object.
511+
509512
#### 4. Avro
510513

511514
The pipeline handles Avro files similarly to how it handles CSV files. No additional changes are required to run
@@ -515,6 +518,9 @@ the pipeline except updating the `--filePattern` parameter. For example:
515518
./gradlew run ... -Pargs="... --filePattern=gs://${PROJECT_ID}-demo-data/*.avro"
516519
```
517520

521+
The original schema of the input file will not be preserved. This solution simplifies the data when it converts the data
522+
to a DLP API request object.
523+
518524
#### 5. CSV files with custom delimiters
519525

520526
The pipeline supports CSV files with a custom delimiter. The delimiter has to be passed in the pipeline option as `--columnDelimiter`.
@@ -535,6 +541,9 @@ No additional changes are required to run the pipeline except updating the `--fi
535541
./gradlew run ... -Pargs="... --filePattern=gs://${PROJECT_ID}-demo-data/*.parquet"
536542
```
537543

544+
The original schema of the input file will not be preserved. This solution simplifies the data when it converts the data
545+
to a DLP API request object.
546+
538547
#### 6. ORC
539548

540549
##### Inspection of ORC files
@@ -562,11 +571,12 @@ written in a BigQuery dataset as tables or an output Cloud Storage bucket as ORC
562571
--outputBucket=<output_storage_bucket> ..."
563572
```
564573

565-
In the above command, replace <i>output_storage_bucket</i> with the URI of the Cloud Storage bucket where you want to store the
566-
de-identified ORC files.
574+
In the above command, replace <i>output_storage_bucket</i> with the URI of the Cloud Storage bucket where you want to
575+
store the de-identified ORC files. The de-identification pipeline allows input files with varying schemas to be
576+
processed in the same pipeline.
567577

568-
The de-identification pipeline supports input files with varying schemas. Currently, it can process only primitive
569-
data types available in ORC format when the results are stored in an output Cloud Storage bucket.
578+
Currently, this solution can process only primitive data types available in ORC format when the results are stored in an
579+
output Cloud Storage bucket.
570580

571581
For sample data in ORC file format, refer to [mock-data](.github/mock-data).
572582

dlp-demo-part-2-dlp-template.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
steps:
15-
- name: gradle:6-jdk11
15+
- name: gradle:8.4.0-jdk17
1616
entrypoint: gradle
1717
args: ['run', '-DmainClass=com.google.swarm.tokenization.tool.DLPTemplateHelper', '--x', 'test', '-Pargs=${_KEK_CONFIG_FILE}']
1818
- name: gcr.io/cloud-builders/gsutil
@@ -29,4 +29,4 @@ steps:
2929
- name: gcr.io/cloud-builders/gsutil
3030
args: ['cp', 'reid-template.json','${_GCS_BUCKET_NAME}/reid-template.json']
3131
- name: gcr.io/cloud-builders/gsutil
32-
args: ['cp', 'inspect-template.json','${_GCS_BUCKET_NAME}/inspect-template.json']
32+
args: ['cp', 'inspect-template.json','${_GCS_BUCKET_NAME}/inspect-template.json']

setup-data-tokeninzation-solution-v2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export KEY_RING_NAME=demo-key-ring
2323
export KEY_NAME=demo-key
2424
export KEK_FILE_NAME=kek.json
2525
export TOKENIZING_ROLE_NAME="dlp_tokenizing_runner"
26-
export PROJECT_NUMBER=$(gcloud projects list --filter=${PROJECT_ID} --format="value(PROJECT_NUMBER)")
26+
export PROJECT_NUMBER=$(gcloud projects list --filter="PROJECT_ID: ${PROJECT_ID}" --format="value(PROJECT_NUMBER)")
2727
export SERVICE_ACCOUNT_NAME=demo-service-account
2828
export REGION=us-central1
2929
export BQ_DATASET_NAME=demo_dataset

src/main/java/com/google/swarm/tokenization/DLPTextToBigQueryStreamingV2.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ private static void runInspectAndDeidPipeline(
243243

244244
case ORC:
245245
records =
246-
inputFiles.apply(
247-
"ReadFromORCFilesAsOrcStruct", ParDo.of(new ORCReaderDoFn(options.getProject())));
246+
inputFiles.apply("ReadORCFiles", ParDo.of(new ORCReaderDoFn(options.getProject())));
248247
break;
249248

250249
default:

src/main/java/com/google/swarm/tokenization/DLPTextToBigQueryStreamingV2PipelineOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public interface DLPTextToBigQueryStreamingV2PipelineOptions extends CommonPipel
145145
*/
146146
void setInitialBackoff(int value);
147147

148-
@Description("Output bucket to write DEID output as csv file")
148+
@Description("Output bucket to write de-identified files in Cloud Storage buckets")
149149
String getOutputBucket();
150150

151151
void setOutputBucket(String outputBucket);

src/main/java/com/google/swarm/tokenization/avro/AvroReaderSplittableDoFn.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class AvroReaderSplittableDoFn
4242
extends DoFn<KV<String, ReadableFile>, KV<String, GenericRecord>> {
4343

4444
public static final Logger LOG = LoggerFactory.getLogger(AvroReaderSplittableDoFn.class);
45-
private final Counter numberOfAvroRecordsIngested =
46-
Metrics.counter(AvroReaderSplittableDoFn.class, "numberOfAvroRecordsIngested");
45+
private final Counter numberOfRowsRead =
46+
Metrics.counter(AvroReaderSplittableDoFn.class, "numberOfRowsRead");
4747
private final Integer splitSize;
4848
private final Integer keyRange;
4949

@@ -82,7 +82,7 @@ public void processElement(ProcessContext c, RestrictionTracker<OffsetRange, Lon
8282

8383
// Output the Avro record
8484
c.outputWithTimestamp(KV.of(fileName, record), Instant.now());
85-
numberOfAvroRecordsIngested.inc();
85+
numberOfRowsRead.inc();
8686
}
8787
}
8888

src/main/java/com/google/swarm/tokenization/beam/DLPDeidentifyText.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,15 @@ static class DeidentifyText
245245
extends DoFn<KV<String, Iterable<Table.Row>>, KV<String, DeidentifyContentResponse>> {
246246

247247
public static final Logger LOG = LoggerFactory.getLogger(DeidentifyText.class);
248+
249+
// Counter to track total number of times DLP Content API calls for DEID failed
248250
private final Counter numberOfDLPRowBagsFailedDeid =
249251
Metrics.counter(DeidentifyText.class, "numberOfDLPRowBagsFailedDeid");
250252

253+
// Counter to track total number of rows that failed to deidentify
254+
private final Counter numberOfDLPRowsFailedDeid =
255+
Metrics.counter(DeidentifyText.class, "numberOfDLPRowsFailedDeid");
256+
251257
private final String projectId;
252258
private final String inspectTemplateName;
253259
private final String deidentifyTemplateName;
@@ -361,6 +367,7 @@ public void processElement(ProcessContext c) throws IOException, InterruptedExce
361367
LOG.warn("Error in DLP API, Retrying...");
362368
} else {
363369
numberOfDLPRowBagsFailedDeid.inc();
370+
numberOfDLPRowsFailedDeid.inc(table.getRowsCount());
364371
LOG.error(
365372
"Retried {} times unsuccessfully. Some records were not de-identified. Exception: {}",
366373
this.dlpApiRetryCount,

src/main/java/com/google/swarm/tokenization/beam/DLPInspectText.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ static class InspectData
231231
private final Counter numberOfDLPRowBagsFailedInspection =
232232
Metrics.counter(DLPInspectText.InspectData.class, "numberOfDLPRowBagsFailedInspection");
233233

234+
private final Counter numberOfDLPRowsFailedInspection =
235+
Metrics.counter(DLPInspectText.InspectData.class, "numberOfDLPRowsFailedInspection");
236+
234237
/**
235238
* @param projectId ID of GCP project that should be used for data inspection.
236239
* @param inspectTemplateName Template name for inspection.
@@ -321,6 +324,7 @@ public void processElement(ProcessContext c) throws IOException, InterruptedExce
321324
LOG.warn("Error in DLP API, Retrying...");
322325
} else {
323326
numberOfDLPRowBagsFailedInspection.inc();
327+
numberOfDLPRowsFailedInspection.inc(table.getRowsCount());
324328
LOG.error(
325329
"Retried {} times unsuccessfully. Not able to inspect some records. Exception: {}",
326330
this.dlpApiRetryCount,

src/main/java/com/google/swarm/tokenization/beam/DLPReidentifyText.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ static class ReidentifyText
261261
private final Counter numberOfDLPRowBagsFailedReid =
262262
Metrics.counter(DLPInspectText.InspectData.class, "numberOfDLPRowBagsFailedReid");
263263

264+
private final Counter numberOfDLPRowsFailedReid =
265+
Metrics.counter(DLPInspectText.InspectData.class, "numberOfDLPRowsFailedReid");
266+
264267
@Setup
265268
public void setup() throws IOException {
266269
requestBuilder = ReidentifyContentRequest.newBuilder().setParent(projectId);
@@ -363,6 +366,7 @@ public void processElement(ProcessContext context) throws IOException, Interrupt
363366
LOG.warn("Error in DLP API, Retrying...");
364367
} else {
365368
numberOfDLPRowBagsFailedReid.inc();
369+
numberOfDLPRowsFailedReid.inc(table.getRowsCount());
366370
LOG.error(
367371
"Retried {} times unsuccessfully. Not able to reidentify some records. Exception: {}",
368372
this.dlpApiRetryCount,

0 commit comments

Comments
 (0)