Skip to content

Commit ccbc878

Browse files
feat: add apiId to environment logs response
Inline the ApiLog schema in openapi-logs.yaml and add the apiId property so consumers can identify which API each log entry belongs to. Map the existing BaseConnectionLog.apiId through to the response.
1 parent 31636b3 commit ccbc878

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

gravitee-apim-rest-api/gravitee-apim-rest-api-management-v2/gravitee-apim-rest-api-management-v2-rest/src/main/resources/openapi/openapi-logs.yaml

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,92 @@ components:
154154
data:
155155
type: array
156156
items:
157-
$ref: "./openapi-apis.yaml#/components/schemas/ApiLog"
157+
$ref: "#/components/schemas/ApiLog"
158158
pagination:
159159
$ref: "./openapi-apis.yaml#/components/schemas/Pagination"
160160
links:
161161
$ref: "./openapi-apis.yaml#/components/schemas/Links"
162162

163+
ApiLog:
164+
type: object
165+
properties:
166+
apiId:
167+
type: string
168+
description: Id of the API.
169+
example: 6c530064-0b2c-4004-9300-640b2ce0047b
170+
timestamp:
171+
type: string
172+
format: date-time
173+
description: The date (as timestamp) of the log.
174+
example: 2023-05-18T12:40:46.184Z
175+
id:
176+
type: string
177+
description: The internal UUID of the Log.
178+
example: 00f8c9e7-78fc-4907-b8c9-e778fc790750
179+
requestId:
180+
type: string
181+
description: The id of the request.
182+
example: 1719d8d1-8d01-48f6-99d8-d18d0178f6d4
183+
method:
184+
$ref: "./openapi-apis.yaml#/components/schemas/HttpMethod"
185+
clientIdentifier:
186+
type: string
187+
description: The client identifier of the request.
188+
example: 12ca17b49af2289436f303e0166030a21e525d266e209267433801a8fd4071a0
189+
plan:
190+
$ref: "./openapi-apis.yaml#/components/schemas/BasePlan"
191+
application:
192+
$ref: "./openapi-apis.yaml#/components/schemas/BaseApplication"
193+
transactionId:
194+
type: string
195+
description: The id of the transaction.
196+
example: 00f8c9e7-78fc-4907-b8c9-e778fc790750
197+
status:
198+
type: integer
199+
description: The response's status.
200+
example: 200
201+
requestEnded:
202+
type: boolean
203+
description: The flag indicating if the request has ended.
204+
example: true
205+
gatewayResponseTime:
206+
type: integer
207+
description: The response time in ms
208+
example: 12
209+
uri:
210+
type: string
211+
description: URI of the request.
212+
example: /my-api
213+
endpoint:
214+
type: string
215+
description: The endpoint URL.
216+
example: "https://my-api-example.com"
217+
message:
218+
type: string
219+
description: The error message.
220+
example: "The timeout period of 1000ms has been exceeded"
221+
errorKey:
222+
type: string
223+
description: The error key.
224+
example: "TIMEOUT_ERROR"
225+
errorComponentName:
226+
type: string
227+
description: The name of the component that generated the error.
228+
example: "security"
229+
errorComponentType:
230+
type: string
231+
description: The type of the component that generated the error.
232+
example: "ENDPOINT"
233+
warnings:
234+
type: array
235+
description: The warning diagnostics
236+
items:
237+
$ref: "./openapi-apis.yaml#/components/schemas/ApiLogDiagnostic"
238+
additionalMetrics:
239+
type: object
240+
additionalProperties: true
241+
description: A map of string keys to values
242+
163243
Filter:
164244
description: |
165245
Filters can be used refine the logs results.

gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/main/java/io/gravitee/apim/core/logs_engine/model/ApiLog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Map;
2121

2222
public record ApiLog(
23+
String apiId,
2324
OffsetDateTime timestamp,
2425
String id,
2526
String requestId,

gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/main/java/io/gravitee/apim/core/logs_engine/use_case/SearchEnvironmentLogsUseCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ private SearchLogsResponse mapResponse(
246246

247247
private ApiLog mapApiLog(BaseConnectionLog item) {
248248
return new ApiLog(
249+
item.getApiId(),
249250
toOffsetDateTime(item.getTimestamp()),
250251
item.getRequestId(),
251252
item.getRequestId(),

gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/test/java/io/gravitee/apim/core/logs_engine/use_case/SearchEnvironmentLogsUseCaseTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ void should_return_empty_response_when_service_returns_no_logs() {
788788
void should_map_response_payload_fully() {
789789
var timestamp = OffsetDateTime.parse("2024-01-01T10:00:00Z");
790790
var connectionLog = BaseConnectionLog.builder()
791+
.apiId("my-api-id")
791792
.timestamp(timestamp.toString())
792793
.requestId("req-id")
793794
.clientIdentifier("client-id")
@@ -821,6 +822,7 @@ void should_map_response_payload_fully() {
821822
var log = response.data().getFirst();
822823

823824
SoftAssertions.assertSoftly(soft -> {
825+
soft.assertThat(log.apiId()).isEqualTo("my-api-id");
824826
soft.assertThat(log.requestId()).isEqualTo("req-id");
825827
soft.assertThat(log.timestamp()).isEqualTo(timestamp);
826828
soft.assertThat(log.clientIdentifier()).isEqualTo("client-id");

0 commit comments

Comments
 (0)