Skip to content

Commit

Permalink
Revise codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Dec 15, 2023
1 parent 025b5db commit 34795af
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
10 changes: 7 additions & 3 deletions server/rpc/connecthelper/useragent.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ import (
// metadata.
func SDKTypeAndVersion(header http.Header) (string, string) {
yorkieUserAgent := header.Get(types.UserAgentKey)
if len(yorkieUserAgent) == 0 {
if yorkieUserAgent == "" {
return "", ""
}

agent := strings.Split(yorkieUserAgent, "/")
return agent[0], agent[1]
split := strings.Split(yorkieUserAgent, "/")
if len(split) != 2 {
return "", ""
}

return split[0], split[1]
}
28 changes: 16 additions & 12 deletions server/rpc/interceptors/admin_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ func (i *AdminAuthInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFu
req.Spec().Procedure,
)

i.backend.Metrics.AddServerHandledCounter(
"unary",
strings.Split(req.Spec().Procedure, "/")[1],
strings.Split(req.Spec().Procedure, "/")[2],
connecthelper.ToRPCCodeString(err),
)
if split := strings.Split(req.Spec().Procedure, "/"); len(split) == 3 {
i.backend.Metrics.AddServerHandledCounter(
"unary",
split[1],
split[2],
connecthelper.ToRPCCodeString(err),
)
}

return res, err
}
Expand Down Expand Up @@ -126,12 +128,14 @@ func (i *AdminAuthInterceptor) WrapStreamingHandler(next connect.StreamingHandle
conn.Spec().Procedure,
)

i.backend.Metrics.AddServerHandledCounter(
"server_stream",
strings.Split(conn.Spec().Procedure, "/")[1],
strings.Split(conn.Spec().Procedure, "/")[2],
connecthelper.ToRPCCodeString(err),
)
if split := strings.Split(conn.Spec().Procedure, "/"); len(split) == 3 {
i.backend.Metrics.AddServerHandledCounter(
"server_stream",
split[1],
split[2],
connecthelper.ToRPCCodeString(err),
)
}

return err
}
Expand Down
31 changes: 17 additions & 14 deletions server/rpc/interceptors/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ func (i *ContextInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc
req.Spec().Procedure,
)

i.backend.Metrics.AddServerHandledCounter(
"unary",
strings.Split(req.Spec().Procedure, "/")[1],
strings.Split(req.Spec().Procedure, "/")[2],
connecthelper.ToRPCCodeString(err),
)
if split := strings.Split(req.Spec().Procedure, "/"); len(split) == 3 {
i.backend.Metrics.AddServerHandledCounter(
"unary",
split[1],
split[2],
connecthelper.ToRPCCodeString(err),
)
}

return res, err
}
Expand Down Expand Up @@ -126,12 +128,14 @@ func (i *ContextInterceptor) WrapStreamingHandler(next connect.StreamingHandlerF
conn.Spec().Procedure,
)

i.backend.Metrics.AddServerHandledCounter(
"server_stream",
strings.Split(conn.Spec().Procedure, "/")[1],
strings.Split(conn.Spec().Procedure, "/")[2],
connecthelper.ToRPCCodeString(err),
)
if split := strings.Split(conn.Spec().Procedure, "/"); len(split) == 3 {
i.backend.Metrics.AddServerHandledCounter(
"server_stream",
split[1],
split[2],
connecthelper.ToRPCCodeString(err),
)
}

return err
}
Expand All @@ -155,8 +159,7 @@ func (i *ContextInterceptor) buildContext(ctx context.Context, header http.Heade
md.APIKey = apiKey
}

authorization := header.Get(types.AuthorizationKey)
if authorization != "" {
if authorization := header.Get(types.AuthorizationKey); authorization != "" {
md.Authorization = authorization
}
ctx = metadata.With(ctx, md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package integration

import (
"context"
"io"
"sync"
"testing"

Expand Down Expand Up @@ -56,7 +55,10 @@ func TestServer(t *testing.T) {
assert.Fail(t, "unexpected ctx done")
return
case wr := <-wrch:
if wr.Err == io.EOF || connect.CodeOf(wr.Err) == connect.CodeCanceled {
// TODO(hackerwins): Define ClientError instead of using ConnectError later.
// For now, we use ConnectError to check whether the stream is closed. To
// simplify the interface, we will define ClientError later.
if connect.CodeOf(wr.Err) == connect.CodeCanceled {
assert.Len(t, wr.Presences, 0)
wg.Done()
return
Expand Down

1 comment on commit 34795af

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark

Benchmark suite Current: 34795af Previous: 3ebef65 Ratio
BenchmarkDocument/constructor_test - ns/op 1406 ns/op 1373 ns/op 1.02
BenchmarkDocument/constructor_test - B/op 1208 B/op 1208 B/op 1
BenchmarkDocument/constructor_test - allocs/op 20 allocs/op 20 allocs/op 1
BenchmarkDocument/status_test - ns/op 795.8 ns/op 796.5 ns/op 1.00
BenchmarkDocument/status_test - B/op 1176 B/op 1176 B/op 1
BenchmarkDocument/status_test - allocs/op 18 allocs/op 18 allocs/op 1
BenchmarkDocument/equals_test - ns/op 7168 ns/op 8302 ns/op 0.86
BenchmarkDocument/equals_test - B/op 6913 B/op 6913 B/op 1
BenchmarkDocument/equals_test - allocs/op 120 allocs/op 120 allocs/op 1
BenchmarkDocument/nested_update_test - ns/op 16085 ns/op 16598 ns/op 0.97
BenchmarkDocument/nested_update_test - B/op 11962 B/op 11962 B/op 1
BenchmarkDocument/nested_update_test - allocs/op 254 allocs/op 254 allocs/op 1
BenchmarkDocument/delete_test - ns/op 21912 ns/op 22626 ns/op 0.97
BenchmarkDocument/delete_test - B/op 15188 B/op 15188 B/op 1
BenchmarkDocument/delete_test - allocs/op 333 allocs/op 333 allocs/op 1
BenchmarkDocument/object_test - ns/op 8349 ns/op 8699 ns/op 0.96
BenchmarkDocument/object_test - B/op 6721 B/op 6721 B/op 1
BenchmarkDocument/object_test - allocs/op 116 allocs/op 116 allocs/op 1
BenchmarkDocument/array_test - ns/op 32341 ns/op 29401 ns/op 1.10
BenchmarkDocument/array_test - B/op 11819 B/op 11819 B/op 1
BenchmarkDocument/array_test - allocs/op 270 allocs/op 270 allocs/op 1
BenchmarkDocument/text_test - ns/op 30611 ns/op 31226 ns/op 0.98
BenchmarkDocument/text_test - B/op 14796 B/op 14795 B/op 1.00
BenchmarkDocument/text_test - allocs/op 468 allocs/op 468 allocs/op 1
BenchmarkDocument/text_composition_test - ns/op 28913 ns/op 29299 ns/op 0.99
BenchmarkDocument/text_composition_test - B/op 18278 B/op 18278 B/op 1
BenchmarkDocument/text_composition_test - allocs/op 477 allocs/op 477 allocs/op 1
BenchmarkDocument/rich_text_test - ns/op 80223 ns/op 82820 ns/op 0.97
BenchmarkDocument/rich_text_test - B/op 38541 B/op 38540 B/op 1.00
BenchmarkDocument/rich_text_test - allocs/op 1147 allocs/op 1147 allocs/op 1
BenchmarkDocument/counter_test - ns/op 16788 ns/op 17386 ns/op 0.97
BenchmarkDocument/counter_test - B/op 10210 B/op 10210 B/op 1
BenchmarkDocument/counter_test - allocs/op 236 allocs/op 236 allocs/op 1
BenchmarkDocument/text_edit_gc_100 - ns/op 2938630 ns/op 2970186 ns/op 0.99
BenchmarkDocument/text_edit_gc_100 - B/op 1655255 B/op 1655326 B/op 1.00
BenchmarkDocument/text_edit_gc_100 - allocs/op 17091 allocs/op 17093 allocs/op 1.00
BenchmarkDocument/text_edit_gc_1000 - ns/op 231255440 ns/op 231735416 ns/op 1.00
BenchmarkDocument/text_edit_gc_1000 - B/op 144362452 B/op 144366033 B/op 1.00
BenchmarkDocument/text_edit_gc_1000 - allocs/op 200992 allocs/op 201007 allocs/op 1.00
BenchmarkDocument/text_split_gc_100 - ns/op 3393462 ns/op 3385194 ns/op 1.00
BenchmarkDocument/text_split_gc_100 - B/op 2313723 B/op 2313331 B/op 1.00
BenchmarkDocument/text_split_gc_100 - allocs/op 16195 allocs/op 16194 allocs/op 1.00
BenchmarkDocument/text_split_gc_1000 - ns/op 286647594 ns/op 296761342 ns/op 0.97
BenchmarkDocument/text_split_gc_1000 - B/op 228882844 B/op 228881832 B/op 1.00
BenchmarkDocument/text_split_gc_1000 - allocs/op 203903 allocs/op 203904 allocs/op 1.00
BenchmarkDocument/text_delete_all_10000 - ns/op 11165958 ns/op 11146892 ns/op 1.00
BenchmarkDocument/text_delete_all_10000 - B/op 5810531 B/op 5810543 B/op 1.00
BenchmarkDocument/text_delete_all_10000 - allocs/op 40674 allocs/op 40675 allocs/op 1.00
BenchmarkDocument/text_delete_all_100000 - ns/op 188021329 ns/op 187188955 ns/op 1.00
BenchmarkDocument/text_delete_all_100000 - B/op 81892408 B/op 81887592 B/op 1.00
BenchmarkDocument/text_delete_all_100000 - allocs/op 411593 allocs/op 411550 allocs/op 1.00
BenchmarkDocument/text_100 - ns/op 228969 ns/op 232235 ns/op 0.99
BenchmarkDocument/text_100 - B/op 118483 B/op 118483 B/op 1
BenchmarkDocument/text_100 - allocs/op 5080 allocs/op 5080 allocs/op 1
BenchmarkDocument/text_1000 - ns/op 2471856 ns/op 2502773 ns/op 0.99
BenchmarkDocument/text_1000 - B/op 1153071 B/op 1153073 B/op 1.00
BenchmarkDocument/text_1000 - allocs/op 50084 allocs/op 50084 allocs/op 1
BenchmarkDocument/array_1000 - ns/op 1241649 ns/op 1267389 ns/op 0.98
BenchmarkDocument/array_1000 - B/op 1091322 B/op 1091268 B/op 1.00
BenchmarkDocument/array_1000 - allocs/op 11826 allocs/op 11826 allocs/op 1
BenchmarkDocument/array_10000 - ns/op 12871361 ns/op 13549731 ns/op 0.95
BenchmarkDocument/array_10000 - B/op 9799489 B/op 9800047 B/op 1.00
BenchmarkDocument/array_10000 - allocs/op 120289 allocs/op 120291 allocs/op 1.00
BenchmarkDocument/array_gc_100 - ns/op 151580 ns/op 153664 ns/op 0.99
BenchmarkDocument/array_gc_100 - B/op 132498 B/op 132498 B/op 1
BenchmarkDocument/array_gc_100 - allocs/op 1248 allocs/op 1248 allocs/op 1
BenchmarkDocument/array_gc_1000 - ns/op 1423344 ns/op 1451255 ns/op 0.98
BenchmarkDocument/array_gc_1000 - B/op 1159017 B/op 1158965 B/op 1.00
BenchmarkDocument/array_gc_1000 - allocs/op 12865 allocs/op 12865 allocs/op 1
BenchmarkDocument/counter_1000 - ns/op 213580 ns/op 215664 ns/op 0.99
BenchmarkDocument/counter_1000 - B/op 192852 B/op 192852 B/op 1
BenchmarkDocument/counter_1000 - allocs/op 5765 allocs/op 5765 allocs/op 1
BenchmarkDocument/counter_10000 - ns/op 2200654 ns/op 2222359 ns/op 0.99
BenchmarkDocument/counter_10000 - B/op 2087769 B/op 2087783 B/op 1.00
BenchmarkDocument/counter_10000 - allocs/op 59772 allocs/op 59772 allocs/op 1
BenchmarkDocument/object_1000 - ns/op 1406468 ns/op 1433455 ns/op 0.98
BenchmarkDocument/object_1000 - B/op 1428067 B/op 1427946 B/op 1.00
BenchmarkDocument/object_1000 - allocs/op 9845 allocs/op 9845 allocs/op 1
BenchmarkDocument/object_10000 - ns/op 14720007 ns/op 14878581 ns/op 0.99
BenchmarkDocument/object_10000 - B/op 12167912 B/op 12167003 B/op 1.00
BenchmarkDocument/object_10000 - allocs/op 100563 allocs/op 100561 allocs/op 1.00
BenchmarkDocument/tree_100 - ns/op 1080966 ns/op 722947 ns/op 1.50
BenchmarkDocument/tree_100 - B/op 943678 B/op 442891 B/op 2.13
BenchmarkDocument/tree_100 - allocs/op 6099 allocs/op 4506 allocs/op 1.35
BenchmarkDocument/tree_1000 - ns/op 77194121 ns/op 48715965 ns/op 1.58
BenchmarkDocument/tree_1000 - B/op 86460556 B/op 35222566 B/op 2.45
BenchmarkDocument/tree_1000 - allocs/op 60114 allocs/op 44119 allocs/op 1.36
BenchmarkDocument/tree_10000 - ns/op 9528690344 ns/op 6243742972 ns/op 1.53
BenchmarkDocument/tree_10000 - B/op 8580988392 B/op 3439193776 B/op 2.50
BenchmarkDocument/tree_10000 - allocs/op 600216 allocs/op 440204 allocs/op 1.36
BenchmarkDocument/tree_delete_all_1000 - ns/op 77493180 ns/op 50492483 ns/op 1.53
BenchmarkDocument/tree_delete_all_1000 - B/op 86990660 B/op 35687345 B/op 2.44
BenchmarkDocument/tree_delete_all_1000 - allocs/op 67753 allocs/op 51744 allocs/op 1.31
BenchmarkDocument/tree_edit_gc_100 - ns/op 3907710 ns/op 2674319 ns/op 1.46
BenchmarkDocument/tree_edit_gc_100 - B/op 4120938 B/op 2099522 B/op 1.96
BenchmarkDocument/tree_edit_gc_100 - allocs/op 14356 allocs/op 11165 allocs/op 1.29
BenchmarkDocument/tree_edit_gc_1000 - ns/op 320325331 ns/op 200656697 ns/op 1.60
BenchmarkDocument/tree_edit_gc_1000 - B/op 383466018 B/op 180293307 B/op 2.13
BenchmarkDocument/tree_edit_gc_1000 - allocs/op 145409 allocs/op 113350 allocs/op 1.28
BenchmarkDocument/tree_split_gc_100 - ns/op 2639860 ns/op 1969140 ns/op 1.34
BenchmarkDocument/tree_split_gc_100 - B/op 2386813 B/op 1363475 B/op 1.75
BenchmarkDocument/tree_split_gc_100 - allocs/op 10341 allocs/op 8735 allocs/op 1.18
BenchmarkDocument/tree_split_gc_1000 - ns/op 192744654 ns/op 133034523 ns/op 1.45
BenchmarkDocument/tree_split_gc_1000 - B/op 221991801 B/op 120284053 B/op 1.85
BenchmarkDocument/tree_split_gc_1000 - allocs/op 112262 allocs/op 96193 allocs/op 1.17
BenchmarkRPC/client_to_server - ns/op 363464148 ns/op 356375965 ns/op 1.02
BenchmarkRPC/client_to_server - B/op 18346264 B/op 16323573 B/op 1.12
BenchmarkRPC/client_to_server - allocs/op 166917 allocs/op 165420 allocs/op 1.01
BenchmarkRPC/client_to_client_via_server - ns/op 611798676 ns/op 607723810 ns/op 1.01
BenchmarkRPC/client_to_client_via_server - B/op 31623400 B/op 34041892 B/op 0.93
BenchmarkRPC/client_to_client_via_server - allocs/op 312386 allocs/op 309871 allocs/op 1.01
BenchmarkRPC/attach_large_document - ns/op 1192894659 ns/op 1463602622 ns/op 0.82
BenchmarkRPC/attach_large_document - B/op 1867436168 B/op 1878647264 B/op 0.99
BenchmarkRPC/attach_large_document - allocs/op 7496 allocs/op 7043 allocs/op 1.06
BenchmarkRPC/adminCli_to_server - ns/op 551090020 ns/op 541741676 ns/op 1.02
BenchmarkRPC/adminCli_to_server - B/op 37615072 B/op 36380716 B/op 1.03
BenchmarkRPC/adminCli_to_server - allocs/op 289698 allocs/op 284616 allocs/op 1.02
BenchmarkLocker - ns/op 65.57 ns/op 65.29 ns/op 1.00
BenchmarkLocker - B/op 16 B/op 16 B/op 1
BenchmarkLocker - allocs/op 1 allocs/op 1 allocs/op 1
BenchmarkLockerParallel - ns/op 39.17 ns/op 38.64 ns/op 1.01
BenchmarkLockerParallel - B/op 0 B/op 0 B/op NaN
BenchmarkLockerParallel - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkLockerMoreKeys - ns/op 154.3 ns/op 138.5 ns/op 1.11
BenchmarkLockerMoreKeys - B/op 15 B/op 15 B/op 1
BenchmarkLockerMoreKeys - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkChange/Push_10_Changes - ns/op 3861495 ns/op 3779429 ns/op 1.02
BenchmarkChange/Push_10_Changes - B/op 125915 B/op 126275 B/op 1.00
BenchmarkChange/Push_10_Changes - allocs/op 1254 allocs/op 1254 allocs/op 1
BenchmarkChange/Push_100_Changes - ns/op 14347035 ns/op 14129092 ns/op 1.02
BenchmarkChange/Push_100_Changes - B/op 649348 B/op 646942 B/op 1.00
BenchmarkChange/Push_100_Changes - allocs/op 6538 allocs/op 6540 allocs/op 1.00
BenchmarkChange/Push_1000_Changes - ns/op 114855876 ns/op 113213707 ns/op 1.01
BenchmarkChange/Push_1000_Changes - B/op 6081570 B/op 6011043 B/op 1.01
BenchmarkChange/Push_1000_Changes - allocs/op 62157 allocs/op 62155 allocs/op 1.00
BenchmarkChange/Pull_10_Changes - ns/op 2891850 ns/op 2837624 ns/op 1.02
BenchmarkChange/Pull_10_Changes - B/op 99859 B/op 100327 B/op 1.00
BenchmarkChange/Pull_10_Changes - allocs/op 951 allocs/op 951 allocs/op 1
BenchmarkChange/Pull_100_Changes - ns/op 4365741 ns/op 4303014 ns/op 1.01
BenchmarkChange/Pull_100_Changes - B/op 256317 B/op 257269 B/op 1.00
BenchmarkChange/Pull_100_Changes - allocs/op 3154 allocs/op 3154 allocs/op 1
BenchmarkChange/Pull_1000_Changes - ns/op 8504532 ns/op 8473189 ns/op 1.00
BenchmarkChange/Pull_1000_Changes - B/op 1394524 B/op 1393414 B/op 1.00
BenchmarkChange/Pull_1000_Changes - allocs/op 26866 allocs/op 26869 allocs/op 1.00
BenchmarkSnapshot/Push_3KB_snapshot - ns/op 17197647 ns/op 16717315 ns/op 1.03
BenchmarkSnapshot/Push_3KB_snapshot - B/op 807969 B/op 807884 B/op 1.00
BenchmarkSnapshot/Push_3KB_snapshot - allocs/op 6543 allocs/op 6541 allocs/op 1.00
BenchmarkSnapshot/Push_30KB_snapshot - ns/op 119283623 ns/op 117501595 ns/op 1.02
BenchmarkSnapshot/Push_30KB_snapshot - B/op 6166384 B/op 6250940 B/op 0.99
BenchmarkSnapshot/Push_30KB_snapshot - allocs/op 62158 allocs/op 62161 allocs/op 1.00
BenchmarkSnapshot/Pull_3KB_snapshot - ns/op 6704261 ns/op 6521588 ns/op 1.03
BenchmarkSnapshot/Pull_3KB_snapshot - B/op 903134 B/op 904310 B/op 1.00
BenchmarkSnapshot/Pull_3KB_snapshot - allocs/op 14878 allocs/op 14878 allocs/op 1
BenchmarkSnapshot/Pull_30KB_snapshot - ns/op 14579879 ns/op 15228711 ns/op 0.96
BenchmarkSnapshot/Pull_30KB_snapshot - B/op 6984446 B/op 6983077 B/op 1.00
BenchmarkSnapshot/Pull_30KB_snapshot - allocs/op 144141 allocs/op 144141 allocs/op 1
BenchmarkSync/memory_sync_10_test - ns/op 6873 ns/op 6917 ns/op 0.99
BenchmarkSync/memory_sync_10_test - B/op 1286 B/op 1286 B/op 1
BenchmarkSync/memory_sync_10_test - allocs/op 38 allocs/op 38 allocs/op 1
BenchmarkSync/memory_sync_100_test - ns/op 52829 ns/op 51493 ns/op 1.03
BenchmarkSync/memory_sync_100_test - B/op 8640 B/op 8650 B/op 1.00
BenchmarkSync/memory_sync_100_test - allocs/op 273 allocs/op 273 allocs/op 1
BenchmarkSync/memory_sync_1000_test - ns/op 603301 ns/op 598451 ns/op 1.01
BenchmarkSync/memory_sync_1000_test - B/op 74275 B/op 74330 B/op 1.00
BenchmarkSync/memory_sync_1000_test - allocs/op 2105 allocs/op 2108 allocs/op 1.00
BenchmarkSync/memory_sync_10000_test - ns/op 7311468 ns/op 7141413 ns/op 1.02
BenchmarkSync/memory_sync_10000_test - B/op 766866 B/op 761330 B/op 1.01
BenchmarkSync/memory_sync_10000_test - allocs/op 20559 allocs/op 20560 allocs/op 1.00
BenchmarkTextEditing - ns/op 18909143457 ns/op 19117165431 ns/op 0.99
BenchmarkTextEditing - B/op 9037951016 B/op 9037584392 B/op 1.00
BenchmarkTextEditing - allocs/op 19923188 allocs/op 19921383 allocs/op 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.