-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OPIK-446] Add duration to trace and span (#883)
* [OPIK-446] Add durartion to trace_span * Fix calc * Fix pr review * OPIK-446 remove spans calculated duration * OPIK-446 remove traces calculated duration * OPIK-446 changed DurationUtils to be a test utility * OPIK-446 changed query builder to use the materialized column --------- Co-authored-by: Ido Berkovich <[email protected]>
- Loading branch information
1 parent
b3e9276
commit a012ea6
Showing
15 changed files
with
670 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../src/main/resources/liquibase/db-app-analytics/migrations/000009_add_duration_columns.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--liquibase formatted sql | ||
--changeset idoberko2:add_duration_columns | ||
|
||
ALTER TABLE ${ANALYTICS_DB_DATABASE_NAME}.spans | ||
ADD COLUMN IF NOT EXISTS duration_millis Nullable(Float64) MATERIALIZED | ||
if(end_time IS NOT NULL AND start_time IS NOT NULL | ||
AND notEquals(start_time, toDateTime64('1970-01-01 00:00:00.000', 9)), | ||
(dateDiff('microsecond', start_time, end_time) / 1000.0), | ||
NULL); | ||
|
||
ALTER TABLE ${ANALYTICS_DB_DATABASE_NAME}.traces | ||
ADD COLUMN IF NOT EXISTS duration_millis Nullable(Float64) MATERIALIZED | ||
if(end_time IS NOT NULL AND start_time IS NOT NULL | ||
AND notEquals(start_time, toDateTime64('1970-01-01 00:00:00.000', 9)), | ||
(dateDiff('microsecond', start_time, end_time) / 1000.0), | ||
NULL); | ||
|
||
--rollback ALTER TABLE ${ANALYTICS_DB_DATABASE_NAME}.spans DROP COLUMN IF EXISTS duration_millis; | ||
--rollback ALTER TABLE ${ANALYTICS_DB_DATABASE_NAME}.traces DROP COLUMN IF EXISTS duration_millis; |
23 changes: 23 additions & 0 deletions
23
apps/opik-backend/src/test/java/com/comet/opik/api/resources/utils/DurationUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.comet.opik.api.resources.utils; | ||
|
||
import lombok.NonNull; | ||
import lombok.experimental.UtilityClass; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
@UtilityClass | ||
public class DurationUtils { | ||
|
||
public static final Double TIME_UNIT = 1_000.0; | ||
|
||
public static Double getDurationInMillisWithSubMilliPrecision(@NonNull Instant startTime, Instant endTime) { | ||
if (endTime == null) { | ||
return null; | ||
} | ||
|
||
long micros = Duration.between(startTime, endTime).toNanos() / TIME_UNIT.longValue(); | ||
return micros / TIME_UNIT; | ||
} | ||
|
||
} |
Oops, something went wrong.