Skip to content

Commit

Permalink
Fix calc
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagohora committed Dec 12, 2024
1 parent 290fb13 commit 1a0a23d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
11 changes: 3 additions & 8 deletions apps/opik-backend/src/main/java/com/comet/opik/api/Span.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.comet.opik.api;

import com.comet.opik.domain.SpanType;
import com.comet.opik.utils.DurationUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
Expand All @@ -14,7 +15,6 @@
import lombok.Builder;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -75,13 +75,8 @@ public static class Public {

@JsonProperty
@JsonView({Span.View.Public.class})
@Schema(accessMode = Schema.AccessMode.READ_ONLY)
@Schema(accessMode = Schema.AccessMode.READ_ONLY, description = "Duration in milliseconds as a decimal number to support sub-millisecond precision")
public Double duration() {
if (endTime == null) {
return null;
}

long micros = Duration.between(startTime, endTime).toNanos() / 1_000;
return micros / 1_000.0;
return DurationUtils.getDurationInSeconds(startTime, endTime);
}
}
11 changes: 3 additions & 8 deletions apps/opik-backend/src/main/java/com/comet/opik/api/Trace.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.comet.opik.api;

import com.comet.opik.utils.DurationUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
Expand All @@ -13,7 +14,6 @@
import lombok.Builder;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -70,13 +70,8 @@ public static class Public {

@JsonProperty
@JsonView({Span.View.Public.class})
@Schema(accessMode = Schema.AccessMode.READ_ONLY)
@Schema(accessMode = Schema.AccessMode.READ_ONLY, description = "Duration in milliseconds as a decimal number to support sub-millisecond precision")
public Double duration() {
if (endTime == null) {
return null;
}

long micros = Duration.between(startTime, endTime).toNanos() / 1_000;
return micros / 1_000.0;
return DurationUtils.getDurationInSeconds(startTime, endTime);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.comet.opik.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 getDurationInSeconds(@NonNull Instant startTime, Instant endTime) {
if (endTime == null) {
return null;
}

long micros = Duration.between(startTime, endTime).toNanos() / TIME_UNIT.longValue();
return micros / TIME_UNIT;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2837,8 +2837,6 @@ void getSpansByProject__whenFilterByDuration__thenReturnSpansFiltered(Operator o
.value(String.valueOf(duration))
.build());

spans.forEach(span -> log.info("Span: {}", span));

getAndAssertPage(workspaceName, projectName, filters, spans, expectedSpans, unexpectedSpans, apiKey);
}

Expand Down

0 comments on commit 1a0a23d

Please sign in to comment.