Skip to content

Commit fcd9748

Browse files
Send who requested the build in the metrics payload
Adds --buildUserEmail and --changeAuthorEmail to uploadMetadata.py, sent as the top-level build_user_email and change_author_email keys on every schema version, v1 per-design fallback included. Blank values are left out. The dashboard stores them on the build and attributes the build to the user who started it, so a "my branches" view can include builds a user started by hand. They describe the build rather than the payload's shape, so they do not bump payload_schema_version. The backend must already register them as metadata before this lands: a v1 message carries metrics at its root, and an older backend would ingest the keys as metrics. Signed-off-by: Miguel Dalberto Pedro <miguel.pedro@precisioninno.com>
1 parent e2e6b16 commit fcd9748

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎flow/util/uploadMetadata.py‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@
5151
"pinned commit rather than the built one. When supplied alongside "
5252
"--jobName the payload is emitted as schema v4.",
5353
)
54+
parser.add_argument(
55+
"--buildUserEmail",
56+
type=str,
57+
default=None,
58+
help="Email of the Jenkins user who started the build by hand "
59+
"(BUILD_USER_EMAIL). Omitted for SCM, timer and branch-scan triggers. "
60+
"The dashboard attributes the build to this user.",
61+
)
62+
parser.add_argument(
63+
"--changeAuthorEmail",
64+
type=str,
65+
default=None,
66+
help="Email of the pull request's author on a PR build "
67+
"(CHANGE_AUTHOR_EMAIL). Empty when the author's GitHub email is private.",
68+
)
5469

5570
# --- PUBSUB args ---
5671
parser.add_argument(
@@ -193,6 +208,23 @@ def resolve_schema_version(args, provenance):
193208
return 4 if provenance else 3
194209

195210

211+
def resolve_requester(args):
212+
"""Who asked for the build, as the payload keys the backend reads.
213+
214+
Blank values are left out rather than sent empty. The keys ride on every
215+
schema version: the backend reads them by presence, and they describe the
216+
build rather than the payload's shape, so they do not bump the version.
217+
"""
218+
requester = {}
219+
for key, value in (
220+
("build_user_email", args.buildUserEmail),
221+
("change_author_email", args.changeAuthorEmail),
222+
):
223+
if value and value.strip():
224+
requester[key] = value.strip()
225+
return requester
226+
227+
196228
def build_pipeline_payload(design_records, args, provenance=None):
197229
"""Return the pipeline-level payload dict.
198230
@@ -220,6 +252,7 @@ def build_pipeline_payload(design_records, args, provenance=None):
220252
# the payload.
221253
if schema_version == 4:
222254
payload.update(provenance)
255+
payload.update(resolve_requester(args))
223256
return payload
224257

225258

@@ -273,6 +306,7 @@ def publish_v1_per_design(publisher, topic_path, design_records, args, provenanc
273306
}
274307
if provenance:
275308
payload.update(provenance)
309+
payload.update(resolve_requester(args))
276310
payload.update(d["metrics"])
277311

278312
message_data = json.dumps(payload, default=str).encode("utf-8")

0 commit comments

Comments
 (0)