Skip to content

Commit 3cb4109

Browse files
committed
Add execution time milliseconds on the result panel header
1 parent ebcf0df commit 3cb4109

File tree

6 files changed

+50
-25
lines changed

6 files changed

+50
-25
lines changed

wasm/internal/ottlplayground.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package internal
2222
import (
2323
"fmt"
2424
"strings"
25+
"time"
2526

2627
"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/ottlplayground/internal"
2728
)
@@ -42,10 +43,11 @@ func registerStatementsExecutor(executor internal.Executor) {
4243
statementsExecutorsLookup[executor.Metadata().ID] = executor
4344
}
4445

45-
func newResult(json string, err string, logs string) map[string]any {
46+
func newResult(json string, err string, logs string, executionTime int64) map[string]any {
4647
v := map[string]any{
47-
"value": json,
48-
"logs": logs,
48+
"value": json,
49+
"logs": logs,
50+
"executionTime": executionTime,
4951
}
5052
if err != "" {
5153
v["error"] = err
@@ -54,7 +56,7 @@ func newResult(json string, err string, logs string) map[string]any {
5456
}
5557

5658
func NewErrorResult(err string, logs string) map[string]any {
57-
return newResult("", err, logs)
59+
return newResult("", err, logs, 0)
5860
}
5961

6062
func takeObservedLogs(executor internal.Executor) string {
@@ -72,6 +74,7 @@ func ExecuteStatements(config, ottlDataType, ottlDataPayload, executorName strin
7274
return NewErrorResult(fmt.Sprintf("unsupported evaluator %s", executorName), "")
7375
}
7476

77+
start := time.Now()
7578
var output []byte
7679
var err error
7780
switch ottlDataType {
@@ -89,7 +92,8 @@ func ExecuteStatements(config, ottlDataType, ottlDataPayload, executorName strin
8992
return NewErrorResult(fmt.Sprintf("unable to run %s statements. Error: %v", ottlDataType, err), takeObservedLogs(executor))
9093
}
9194

92-
return newResult(string(output), "", takeObservedLogs(executor))
95+
executionTime := time.Since(start).Milliseconds()
96+
return newResult(string(output), "", takeObservedLogs(executor), executionTime)
9397
}
9498

9599
func StatementsExecutors() []any {

wasm/internal/ottlplayground_test.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ func Test_NewErrorResult(t *testing.T) {
3434
logs := "execution logs"
3535
err := "error"
3636
expected := map[string]any{
37-
"value": "",
38-
"logs": logs,
39-
"error": err,
37+
"value": "",
38+
"logs": logs,
39+
"error": err,
40+
"executionTime": int64(0),
4041
}
4142

4243
result := NewErrorResult(err, logs)
@@ -50,14 +51,11 @@ func Test_ExecuteStatements_UnsupportedExecutor(t *testing.T) {
5051
executorName := "unsupported_processor"
5152

5253
expectedError := fmt.Sprintf("unsupported evaluator %s", executorName)
53-
expected := map[string]any{
54-
"value": "",
55-
"logs": "",
56-
"error": expectedError,
57-
}
58-
5954
result := ExecuteStatements(config, otlpDataType, otlpDataPayload, executorName)
60-
assert.Equal(t, expected, result)
55+
assert.Equal(t, "", result["value"])
56+
assert.Equal(t, "", result["logs"])
57+
assert.Equal(t, expectedError, result["error"])
58+
assert.GreaterOrEqual(t, result["executionTime"], int64(0))
6159
}
6260

6361
func Test_ExecuteStatements_UnsupportedOTLPType(t *testing.T) {
@@ -67,14 +65,12 @@ func Test_ExecuteStatements_UnsupportedOTLPType(t *testing.T) {
6765
executorName := "transform_processor"
6866

6967
expectedError := fmt.Sprintf("unsupported OTLP data type %s", otlpDataType)
70-
expected := map[string]any{
71-
"value": "",
72-
"logs": "",
73-
"error": expectedError,
74-
}
7568

7669
result := ExecuteStatements(config, otlpDataType, otlpDataPayload, executorName)
77-
assert.Equal(t, expected, result)
70+
assert.Equal(t, "", result["value"])
71+
assert.Equal(t, "", result["logs"])
72+
assert.Equal(t, expectedError, result["error"])
73+
assert.GreaterOrEqual(t, result["executionTime"], int64(0))
7874
}
7975

8076
func Test_ExecuteStatements(t *testing.T) {
@@ -149,9 +145,11 @@ func Test_ExecuteStatements(t *testing.T) {
149145
assert.Empty(t, result["value"])
150146
expectedErrorMsg := fmt.Sprintf("unable to run %s statements. Error: %v", tt.otlpDataType, tt.expectedError)
151147
assert.Contains(t, result["error"], expectedErrorMsg)
148+
assert.Equal(t, result["executionTime"], int64(0))
152149
} else {
153150
assert.Equal(t, tt.expectedOutput, result["value"])
154151
assert.NotContains(t, result, "error")
152+
assert.GreaterOrEqual(t, result["executionTime"], int64(0))
155153
}
156154

157155
mockExecutor.AssertExpectations(t)

web/src/components/examples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const TRANSFORM_PROCESSOR_CONFIG_EXAMPLES = [
102102
' - context: log\n' +
103103
' statements:\n' +
104104
' - merge_maps(cache, ParseJSON(body), "upsert") where IsMatch(body, "^\\\\{")\n' +
105-
' - set(time, Time(cache["timestamp"], "%Y-%m-%dT%H:%M:%SZ"))\n'+
105+
' - set(time, Time(cache["timestamp"], "%Y-%m-%dT%H:%M:%SZ"))\n' +
106106
' - set(severity_text, cache["level"])\n' +
107107
' - set(body, cache["message"])',
108108
payload:

web/src/components/panels/result-panel.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ export class PlaygroundResultPanel extends LitElement {
8484
<div class="header">
8585
<span><strong>Result</strong></span>
8686
</div>
87+
${
88+
this.result?.executionTime
89+
? html`
90+
<div
91+
class="execution-time-header"
92+
title="Execution time"
93+
>
94+
<span>
95+
<span
96+
>${this.result?.executionTime} ms</span
97+
>
98+
</span>
99+
</div>
100+
`
101+
: nothing
102+
}
87103
</div>
88104
<div>
89105
<div class="result-panel-view">

web/src/components/panels/result-panel.styles.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ const resultPanelStyle = css`
5151
}
5252
}
5353
54+
.result-panel-controls .execution-time-header {
55+
float: right;
56+
font-size: 12px;
57+
color: gray;
58+
cursor: default;
59+
}
60+
5461
.result-panel-content {
5562
overflow: auto;
5663
height: calc(100% - 74px);

web/src/components/playground.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ export class Playground extends LitElement {
103103

104104
_initState() {
105105
let urlStateData = this._loadURLBase64DataHash();
106-
let version = urlStateData?.version
107-
if (!version || !this._versions?.some(it => it.version === version)) {
108-
version = this._versions?.[0]?.version;
106+
let version = urlStateData?.version;
107+
if (!version || !this._versions?.some((it) => it.version === version)) {
108+
version = this._versions?.[0]?.version;
109109
}
110110

111111
if (urlStateData) {

0 commit comments

Comments
 (0)