Skip to content

Commit 849837d

Browse files
ishleenk17agithomas
authored andcommitted
Update Vertex AI fields to snake case in pipeline (elastic#15604)
* Update Vertex AI fields to snake case in pipeline * update PR ID * Update to renaming all fields with painless * Add safety_ratings mappings
1 parent 23d82fc commit 849837d

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

packages/gcp_vertexai/changelog.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# newer versions go on top
22
- version: "1.4.0-next"
33
changes:
4+
- description: Update the mapping to snake case in pipeline.
5+
type: enhancement
6+
link: https://github.com/elastic/integrations/pull/15604
47
- description: Add support for Vertex AI Prompt Response Logs datastream.
58
type: enhancement
69
link: https://github.com/elastic/integrations/pull/15435

packages/gcp_vertexai/data_stream/prompt_response_logs/elasticsearch/ingest_pipeline/default.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,41 @@ processors:
3737
field: event.action
3838
copy_from: gcp.vertexai.prompt_response_logs.api_method
3939
if: ctx.gcp?.vertexai?.prompt_response_logs?.api_method != null
40-
40+
41+
# Rename camelCase fields to snake_case
42+
43+
- script:
44+
lang: painless
45+
source: |
46+
Map keysToSnakeCase(Map m) {
47+
def regex = /_?([a-z])([A-Z]+)/;
48+
def snakeCaseMap = [:];
49+
for (entry in m.entrySet()) {
50+
def k = entry.getKey();
51+
def v = entry.getValue();
52+
if (v instanceof Map) {
53+
v = keysToSnakeCase(v);
54+
} else if (v instanceof List) {
55+
for (int i = 0; i < v.size(); i++) {
56+
def item = v.get(i);
57+
if (item instanceof Map) {
58+
v.set(i, keysToSnakeCase(item));
59+
}
60+
}
61+
}
62+
k = regex.matcher(k).replaceAll('$1_$2').toLowerCase();
63+
snakeCaseMap.put(k, v);
64+
}
65+
return snakeCaseMap;
66+
}
67+
68+
if (ctx.gcp?.vertexai?.prompt_response_logs?.full_request != null) {
69+
ctx.gcp.vertexai.prompt_response_logs.full_request = keysToSnakeCase(ctx.gcp.vertexai.prompt_response_logs.full_request);
70+
}
71+
if (ctx.gcp?.vertexai?.prompt_response_logs?.full_response != null) {
72+
ctx.gcp.vertexai.prompt_response_logs.full_response = keysToSnakeCase(ctx.gcp.vertexai.prompt_response_logs.full_response);
73+
}
74+
4175
4276
# Remove null and empty values recursively
4377
- script:

0 commit comments

Comments
 (0)