Skip to content

[improvement](fe) Improve audit logs for S3 streaming insert jobs - #67489

Open
JNSimba wants to merge 2 commits into
apache:masterfrom
JNSimba:fix/streaming-insert-audit-log
Open

[improvement](fe) Improve audit logs for S3 streaming insert jobs#67489
JNSimba wants to merge 2 commits into
apache:masterfrom
JNSimba:fix/streaming-insert-audit-log

Conversation

@JNSimba

@JNSimba JNSimba commented Sep 3, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary:

S3 streaming insert tasks execute internal INSERT statements without emitting query audit events. This makes it difficult to identify the exact files imported after wildcard paths are resolved.

This change emits internal audit events only for S3 streaming insert tasks. The audited statement contains the rewritten S3 URI and masks sensitive TVF properties. Both successful and failed executions are recorded. CDC streaming insert tasks keep the existing behavior and do not emit these audit events.

Release note

S3 streaming insert jobs now record internal INSERT audit logs with resolved file paths and masked credentials.

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test
    • No need to test or manual test.
  • Behavior changed:

    • Yes. S3 streaming insert tasks now emit internal audit events.
    • No.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@JNSimba
JNSimba requested a lite review from Copilot September 3, 2026 10:14
@JNSimba

JNSimba commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

/review

@JNSimba

JNSimba commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

run buildall

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Adds internal query audit logging for S3 streaming insert tasks so audit events capture resolved S3 file paths (post-wildcard expansion) while masking sensitive TVF properties; also records audit events for both success and failure cases. CDC streaming insert behavior remains unchanged (no internal audit events).

Changes:

  • Emit internal INSERT audit events for S3 streaming insert tasks with rewritten S3 URI and masked TVF properties.
  • Ensure failed S3 streaming inserts also generate error audit events.
  • Add regression/unit tests validating S3 audit emission and CDC non-emission.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
fe/fe-core/src/main/java/org/apache/doris/job/extensions/insert/streaming/StreamingInsertTask.java Adds audit-enabled path for S3 streaming inserts, constructs masked/re-written audit SQL, and logs audit events on completion/failure.
fe/fe-core/src/test/java/org/apache/doris/job/extensions/insert/streaming/StreamingInsertTaskAuditTest.java Introduces tests to assert S3 audit events are emitted (success/failure) and CDC tasks do not emit audit events.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Automated review status: complete after round 2 convergence. I am requesting changes for two distinct audit-correctness defects described inline.

Critical checkpoints:

  • Goal and functional correctness: S3-only gating, success/error state capture, and CDC exclusion are generally coherent, but valid S3 inputs can either lose the required audit event or retain the unresolved wildcard beside the resolved URI.
  • Lifecycle, concurrency, and error handling: I traced setup, each retry attempt, success, existing and synthesized ERR states, cancellation, cleanup, and asynchronous event ownership. Each command attempt reaches the audit finally block, the public audit helper contains its own failures, and the queued event does not retain task-owned context. No additional distinct lifecycle defect remained.
  • SQL reconstruction and sensitive data: recognized credential aliases remain masked, but the rewritten property map is a display representation rather than reparsable SQL. This causes the P1 event-loss finding; case-preserving URI rewriting causes the separate P2 accuracy finding.
  • Scope, parallel paths, compatibility, and performance: CDC behavior is unchanged. No persistence, protocol, configuration, migration, or material performance regression is introduced by this two-file change.
  • Tests: the new unit tests cover basic S3 OK/ERR events and CDC non-emission, but they inject a lowercase, syntax-neutral rewritten map and therefore miss both accepted defects. Per the review-run instructions, I did not run builds locally. Live CheckStyle passed; FE UT, compile, and performance checks were still pending at submission time.
  • Existing review context: all three existing inline threads were treated as duplicate fences and were not repeated.

User focus: no additional focus was supplied, so the full PR was reviewed.

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 16893 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 050bebb9a1a971184cb70e4d656742a641493945, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17567	3107	3101	3101
q2	2093	269	235	235
q3	10224	875	525	525
q4	4671	247	201	201
q5	7685	548	378	378
q6	138	114	92	92
q7	545	504	390	390
q8	9241	932	980	932
q9	3406	2390	2367	2367
q10	6487	870	736	736
q11	408	204	181	181
q12	614	261	200	200
q13	18122	1535	1162	1162
q14	154	150	138	138
q15	q16	432	394	368	368
q17	1402	876	867	867
q18	3122	2257	2235	2235
q19	1273	826	728	728
q20	367	290	199	199
q21	5611	1635	1818	1635
q22	331	271	223	223
Total cold run time: 93893 ms
Total hot run time: 16893 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3477	3439	3390	3390
q2	525	401	364	364
q3	2215	2339	2117	2117
q4	1192	1167	910	910
q5	2185	2117	2136	2117
q6	169	118	85	85
q7	1045	935	839	839
q8	1616	1411	1418	1411
q9	3135	3101	3090	3090
q10	1828	1786	1681	1681
q11	355	272	251	251
q12	456	429	344	344
q13	1486	1529	1145	1145
q14	179	176	156	156
q15	q16	405	413	360	360
q17	3606	3318	3165	3165
q18	4789	4393	4723	4393
q19	877	932	880	880
q20	1000	972	853	853
q21	3883	3202	3252	3202
q22	391	372	332	332
Total cold run time: 34814 ms
Total hot run time: 31085 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 82110 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 050bebb9a1a971184cb70e4d656742a641493945, data reload: false

query5	4236	423	342	342
query6	396	138	124	124
query7	4923	402	228	228
query8	289	130	115	115
query9	8672	2891	2900	2891
query10	401	217	171	171
query11	5370	1033	915	915
query12	119	70	72	70
query13	1207	466	327	327
query14	6157	2206	2098	2098
query14_1	1987	1965	1966	1965
query15	174	122	112	112
query16	931	373	361	361
query17	832	466	364	364
query18	2354	326	243	243
query19	175	154	117	117
query20	74	70	70	70
query21	212	102	88	88
query22	5439	5479	5280	5280
query23	6903	6274	5946	5946
query23_1	5997	6035	6001	6001
query24	7297	1119	766	766
query24_1	777	785	794	785
query25	436	313	285	285
query26	1220	240	133	133
query27	2781	413	257	257
query28	4691	1514	1501	1501
query29	945	444	356	356
query30	247	153	138	138
query31	831	406	339	339
query32	154	81	73	73
query33	459	222	184	184
query34	1002	837	473	473
query35	399	414	341	341
query36	591	570	554	554
query37	120	78	73	73
query38	1001	854	822	822
query39	495	486	477	477
query39_1	458	463	456	456
query40	207	92	81	81
query41	59	57	56	56
query42	79	75	73	73
query43	249	248	222	222
query44	1034	548	565	548
query45	114	111	134	111
query46	754	826	534	534
query47	759	777	721	721
query48	311	312	220	220
query49	553	248	210	210
query50	712	249	196	196
query51	8182	8167	8150	8150
query52	66	71	66	66
query53	186	201	144	144
query54	230	168	158	158
query55	82	58	53	53
query56	221	288	157	157
query57	674	686	650	650
query58	202	181	172	172
query59	1259	1240	1101	1101
query60	232	184	174	174
query61	115	115	115	115
query62	363	199	177	177
query63	174	137	138	137
query64	2801	692	596	596
query65	1678	1614	1635	1614
query66	1898	256	208	208
query67	9777	9575	9642	9575
query68	2735	1123	752	752
query69	338	219	204	204
query70	677	616	626	616
query71	253	175	163	163
query72	2373	1710	1564	1564
query73	629	634	359	359
query74	1576	1219	1149	1149
query75	1170	1101	942	942
query76	2299	718	558	558
query77	251	256	223	223
query78	4030	3693	3171	3171
query79	2798	865	591	591
query80	1575	324	268	268
query81	513	155	134	134
query82	1103	123	95	95
query83	281	205	189	189
query84	309	112	89	89
query85	820	364	300	300
query86	427	174	168	168
query87	1007	967	906	906
query88	2813	2119	2106	2106
query89	281	195	174	174
query90	1945	127	126	126
query91	129	119	99	99
query92	78	70	71	70
query93	1501	1178	719	719
query94	672	282	229	229
query95	538	324	228	228
query96	793	535	256	256
query97	1041	1024	1011	1011
query98	170	132	136	132
query99	433	358	310	310
Total cold run time: 178748 ms
Total hot run time: 82110 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.51 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 050bebb9a1a971184cb70e4d656742a641493945, data reload: false

query1	0.00	0.01	0.00
query2	0.07	0.04	0.03
query3	0.25	0.11	0.12
query4	1.60	0.09	0.10
query5	0.17	0.16	0.16
query6	1.24	0.69	0.67
query7	0.03	0.01	0.01
query8	0.04	0.03	0.03
query9	0.28	0.21	0.21
query10	0.35	0.32	0.33
query11	0.16	0.12	0.12
query12	0.15	0.13	0.12
query13	0.32	0.31	0.30
query14	0.46	0.44	0.44
query15	0.37	0.34	0.35
query16	0.23	0.23	0.24
query17	0.74	0.72	0.67
query18	0.18	0.16	0.17
query19	1.13	1.12	1.12
query20	0.02	0.01	0.01
query21	15.44	0.16	0.11
query22	5.04	0.04	0.04
query23	16.20	0.24	0.10
query24	3.04	0.34	0.25
query25	0.10	0.05	0.03
query26	0.79	0.16	0.13
query27	0.04	0.02	0.03
query28	3.66	0.54	0.26
query29	12.45	3.19	2.56
query30	0.26	0.13	0.10
query31	2.75	0.36	0.17
query32	3.54	0.33	0.23
query33	1.35	1.39	1.36
query34	15.37	2.18	1.74
query35	1.73	1.73	1.73
query36	0.45	0.30	0.29
query37	0.05	0.04	0.04
query38	0.05	0.03	0.03
query39	0.04	0.02	0.02
query40	0.12	0.08	0.08
query41	0.08	0.03	0.03
query42	0.03	0.02	0.03
query43	0.03	0.03	0.03
Total cold run time: 90.4 s
Total hot run time: 14.51 s

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 25.29% (22/87) 🎉
Increment coverage report
Complete coverage report

@JNSimba

JNSimba commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

run buildall

@JNSimba

JNSimba commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall: request changes. One distinct P1 remains on the reviewed head; previously raised quote escaping, cancellation/finally isolation, replacement cardinality, URI case handling, and CDC-test concerns were treated as duplicate fences and were not repeated.

Finding

  • The new audit reconstruction mixes ANTLR code-point coordinates with Java UTF-16 string indexes. A valid supplementary-Unicode S3 key can therefore suppress the audit event for a successful load or leave its final statement malformed.

Checkpoint conclusions

  • Goal/data correctness and special cases: ordinary BMP-only S3 success/error attempts preserve final state, timestamp, executor statistics, resolved file URI, and sensitive-value masking. The Unicode range failure prevents the audit feature from being correct for all admitted S3 object keys.
  • Concurrency, lifecycle, and transactions: each retry builds fresh context/command/executor/audit state, and auditing happens after the INSERT execution path. The concrete cancellation cleanup race is already covered by an existing thread. No additional transaction, lock-order, or unbounded-retention issue survived review.
  • Configuration, compatibility, storage, and performance: no configuration, persisted format, FE/BE protocol, rolling-upgrade, or storage-layout change is introduced. The additional parsing/rendering is per S3 batch; no separate performance defect was substantiated.
  • Tests: the new FE unit test covers S3 success/failure events, internal classification, resolved URI, masking, timestamp, URI case folding, and unchanged CDC behavior. Its reflective setup and ASCII-only fixture miss the reported Unicode failure. Per the review-runner instructions, I did not run builds or tests.
  • Scope, parallel paths, and focus: the production change is focused on S3 audit emission; CDC remains unchanged. No additional user-provided review focus was supplied, so the full PR was reviewed.

Review completeness: complete after two rounds of whole-PR and risk-focused review; no unresolved candidates remain.

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 16576 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 7771587d3a85c3ed1c60c6bded10af419dbf4a4f, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17001	2992	2989	2989
q2	2082	267	219	219
q3	10089	877	516	516
q4	4664	250	197	197
q5	7680	655	381	381
q6	132	116	100	100
q7	551	503	384	384
q8	9227	884	928	884
q9	3471	2399	2355	2355
q10	6509	855	722	722
q11	397	198	176	176
q12	625	259	199	199
q13	18164	1521	1143	1143
q14	154	147	135	135
q15	q16	433	392	364	364
q17	1346	913	810	810
q18	3067	2199	2178	2178
q19	1263	914	741	741
q20	388	288	200	200
q21	5544	1659	1884	1659
q22	320	266	224	224
Total cold run time: 93107 ms
Total hot run time: 16576 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3367	3287	3276	3276
q2	490	390	351	351
q3	2185	2309	2157	2157
q4	1167	1141	872	872
q5	2121	2097	2077	2077
q6	161	123	84	84
q7	1041	957	827	827
q8	1582	1369	1374	1369
q9	3083	3065	3088	3065
q10	1840	1784	1615	1615
q11	347	266	246	246
q12	444	430	338	338
q13	1475	1515	1138	1138
q14	169	175	168	168
q15	q16	384	397	359	359
q17	3555	3267	3217	3217
q18	4702	4353	4658	4353
q19	828	801	796	796
q20	957	1147	852	852
q21	3805	3077	3287	3077
q22	394	335	306	306
Total cold run time: 34097 ms
Total hot run time: 30543 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 82031 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 7771587d3a85c3ed1c60c6bded10af419dbf4a4f, data reload: false

query5	4253	410	327	327
query6	388	142	119	119
query7	4960	401	228	228
query8	293	119	119	119
query9	8705	2887	2890	2887
query10	389	223	189	189
query11	5386	1035	909	909
query12	115	74	74	74
query13	1199	459	322	322
query14	6064	2198	2077	2077
query14_1	1985	1992	1982	1982
query15	179	118	108	108
query16	927	363	348	348
query17	811	467	374	374
query18	2337	335	250	250
query19	165	140	113	113
query20	78	72	71	71
query21	208	102	85	85
query22	5261	5409	5328	5328
query23	6656	6134	5947	5947
query23_1	5919	6083	6154	6083
query24	7153	1081	770	770
query24_1	780	789	802	789
query25	438	314	255	255
query26	1230	236	140	140
query27	2771	415	252	252
query28	4614	1516	1512	1512
query29	936	444	364	364
query30	248	157	130	130
query31	828	399	328	328
query32	134	73	80	73
query33	465	230	181	181
query34	1008	865	507	507
query35	409	408	346	346
query36	570	537	552	537
query37	119	82	72	72
query38	992	848	816	816
query39	506	489	489	489
query39_1	468	437	475	437
query40	214	92	82	82
query41	57	58	56	56
query42	79	74	72	72
query43	242	243	206	206
query44	1022	553	550	550
query45	138	104	102	102
query46	750	860	548	548
query47	766	747	711	711
query48	317	303	236	236
query49	526	239	194	194
query50	712	264	190	190
query51	8161	8010	7988	7988
query52	70	71	57	57
query53	191	196	146	146
query54	228	166	150	150
query55	70	56	57	56
query56	225	160	175	160
query57	698	646	708	646
query58	190	165	159	159
query59	1232	1197	1087	1087
query60	239	197	168	168
query61	116	145	128	128
query62	358	220	203	203
query63	175	153	148	148
query64	2695	669	611	611
query65	1634	1593	1623	1593
query66	1874	270	199	199
query67	9808	9757	9665	9665
query68	2995	1153	701	701
query69	356	225	213	213
query70	665	620	637	620
query71	259	173	164	164
query72	2333	1774	1548	1548
query73	632	593	347	347
query74	2003	1220	1135	1135
query75	1182	1096	959	959
query76	2272	734	536	536
query77	252	272	216	216
query78	3955	3634	3188	3188
query79	2806	848	591	591
query80	1578	317	288	288
query81	520	157	134	134
query82	626	128	100	100
query83	288	211	188	188
query84	299	108	90	90
query85	820	359	290	290
query86	477	172	176	172
query87	989	972	887	887
query88	2849	2130	2117	2117
query89	291	195	173	173
query90	2069	128	130	128
query91	132	121	102	102
query92	99	70	67	67
query93	1898	1066	697	697
query94	642	248	228	228
query95	513	244	227	227
query96	842	578	276	276
query97	1094	1056	1007	1007
query98	177	140	133	133
query99	419	337	302	302
Total cold run time: 178478 ms
Total hot run time: 82031 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.65 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 7771587d3a85c3ed1c60c6bded10af419dbf4a4f, data reload: false

query1	0.01	0.00	0.01
query2	0.08	0.04	0.04
query3	0.26	0.10	0.10
query4	1.61	0.10	0.10
query5	0.18	0.15	0.16
query6	1.26	0.69	0.71
query7	0.03	0.01	0.00
query8	0.04	0.03	0.03
query9	0.29	0.20	0.21
query10	0.35	0.34	0.34
query11	0.16	0.12	0.12
query12	0.15	0.12	0.11
query13	0.30	0.30	0.30
query14	0.44	0.43	0.46
query15	0.37	0.34	0.35
query16	0.21	0.22	0.23
query17	0.71	0.68	0.72
query18	0.17	0.17	0.16
query19	1.13	1.17	1.14
query20	0.02	0.01	0.01
query21	15.44	0.17	0.13
query22	5.05	0.04	0.04
query23	16.17	0.26	0.10
query24	3.01	0.30	0.26
query25	0.10	0.04	0.03
query26	0.77	0.16	0.13
query27	0.04	0.03	0.02
query28	3.65	0.54	0.28
query29	12.49	3.18	2.60
query30	0.24	0.10	0.11
query31	2.75	0.36	0.17
query32	3.53	0.31	0.23
query33	1.36	1.42	1.52
query34	15.40	2.15	1.75
query35	1.74	1.72	1.74
query36	0.44	0.29	0.28
query37	0.06	0.04	0.04
query38	0.05	0.03	0.03
query39	0.03	0.02	0.03
query40	0.11	0.08	0.08
query41	0.07	0.02	0.03
query42	0.03	0.02	0.02
query43	0.04	0.03	0.02
Total cold run time: 90.34 s
Total hot run time: 14.65 s

@JNSimba

JNSimba commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

run p0

1 similar comment
@JNSimba

JNSimba commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

run p0

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 20.16% (25/124) 🎉
Increment coverage report
Complete coverage report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants