Skip to content

Commit c8c1078

Browse files
ProfiledPlan: expose existence for all metrics (#687)
* Move internal summary types and values into internal package * ProfiledPlan: expose existence for all metrics * Use `(T, bool)` instead of `hasXyz` methods. * Rename interface `Profile` to `QueryProfile` * Rename `idb.Summary`'s `ProfiledPlan` to `Profile` * Make `QueryProfile.Time()` return `time.Duration` instead of int64 --------- Co-authored-by: Stephen Cathcart <stephen.cathcart@neo4j.com>
1 parent a34303a commit c8c1078

26 files changed

Lines changed: 748 additions & 274 deletions

neo4j/db/summary.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,47 @@ package db
1919

2020
// Definitions of these should correspond to public API
2121
//
22-
// Deprecated: Use QueryType instead. This will be removed in a future release.
22+
// Deprecated: Use neo4j.QueryType instead. This will be removed in a future release.
2323
type StatementType int
2424

2525
const (
26-
// Deprecated: Use QueryTypeUnknown instead. This will be removed in a future release.
26+
// Deprecated: Use neo4j.QueryTypeUnknown instead. This will be removed in a future release.
2727
StatementTypeUnknown StatementType = 0
28-
// Deprecated: Use QueryTypeRead instead. This will be removed in a future release.
28+
// Deprecated: Use neo4j.QueryTypeReadOnly instead. This will be removed in a future release.
2929
StatementTypeRead StatementType = 1
30-
// Deprecated: Use QueryTypeReadWrite instead. This will be removed in a future release.
30+
// Deprecated: Use neo4j.QueryTypeReadWrite instead. This will be removed in a future release.
3131
StatementTypeReadWrite StatementType = 2
32-
// Deprecated: Use QueryTypeWrite instead. This will be removed in a future release.
32+
// Deprecated: Use neo4j.QueryTypeWriteOnly instead. This will be removed in a future release.
3333
StatementTypeWrite StatementType = 3
34-
// Deprecated: Use QueryTypeSchemaWrite instead. This will be removed in a future release.
34+
// Deprecated: Use neo4j.QueryTypeSchemaWrite instead. This will be removed in a future release.
3535
StatementTypeSchemaWrite StatementType = 4
3636
)
3737

3838
// QueryType defines the type of the query
39+
//
40+
// Deprecated: Use neo4j.QueryType instead. This will be removed in a future release.
3941
type QueryType = StatementType
4042

4143
const (
4244
// QueryTypeUnknown identifies an unknown query type
45+
//
46+
// Deprecated: Use neo4j.QueryTypeUnknown instead. This will be removed in a future release.
4347
QueryTypeUnknown QueryType = 0
4448
// QueryTypeRead identifies a read query
49+
//
50+
// Deprecated: Use neo4j.QueryTypeReadOnly instead. This will be removed in a future release.
4551
QueryTypeRead QueryType = 1
4652
// QueryTypeReadWrite identifies a read-write query
53+
//
54+
// Deprecated: Use neo4j.QueryTypeReadWrite instead. This will be removed in a future release.
4755
QueryTypeReadWrite QueryType = 2
4856
// QueryTypeWrite identifies a write query
57+
//
58+
// Deprecated: Use neo4j.QueryTypeWriteOnly instead. This will be removed in a future release.
4959
QueryTypeWrite QueryType = 3
5060
// QueryTypeSchemaWrite identifies a schema-write query
61+
//
62+
// Deprecated: Use neo4j.QueryTypeSchemaWrite instead. This will be removed in a future release.
5163
QueryTypeSchemaWrite QueryType = 4
5264
)
5365

@@ -73,6 +85,8 @@ const (
7385
// plans. The statement starts with the root plan. Each sub-plan is of a specific operator, which describes what
7486
// that part of the plan does - for instance, perform an index lookup or filter results.
7587
// The Neo4j Manual contains a reference of the available operator types, and these may differ across Neo4j versions.
88+
//
89+
// Deprecated: Internal type. This will be removed in a future release.
7690
type Plan struct {
7791
// Operator is the operation this plan is performing.
7892
Operator string
@@ -90,6 +104,8 @@ type Plan struct {
90104

91105
// ProfiledPlan is the same as a regular Plan - except this plan has been executed, meaning it also
92106
// contains detailed information about how much work each step of the plan incurred on the database.
107+
//
108+
// Deprecated: Internal type. This will be removed in a future release.
93109
type ProfiledPlan struct {
94110
// Operator contains the operation this plan is performing.
95111
Operator string
@@ -113,6 +129,7 @@ type ProfiledPlan struct {
113129
Time int64
114130
}
115131

132+
// Deprecated: Internal type. This will be removed in a future release.
116133
type StreamSummary struct {
117134
HadRecord bool
118135
HadKey bool
@@ -131,6 +148,8 @@ type Notification struct {
131148
// GqlStatusObject represents a GqlStatusObject generated when executing a statement.
132149
// A GqlStatusObject can be visualized in a client pinpointing problems or other information about the statement.
133150
// Contrary to failures or errors, GqlStatusObjects do not affect the execution of the statement.
151+
//
152+
// Deprecated: Internal type. This will be removed in a future release.
134153
type GqlStatusObject struct {
135154
// Deprecated: for backward compatibility with Notification.Code only.
136155
Code string
@@ -175,6 +194,8 @@ type GqlStatusObject struct {
175194
}
176195

177196
// InputPosition contains information about a specific position in a statement
197+
//
198+
// Deprecated: Internal type. This will be removed in a future release.
178199
type InputPosition struct {
179200
// Offset contains the character offset referred to by this position; offset numbers start at 0.
180201
Offset int
@@ -189,6 +210,7 @@ type ProtocolVersion struct {
189210
Minor int
190211
}
191212

213+
// Deprecated: Internal type. This will be removed in a future release.
192214
type Summary struct {
193215
Bookmark string
194216
StmntType StatementType

neo4j/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ func (d *driver) VerifyAuthentication(ctx context.Context, auth *AuthToken) (err
527527
// summary, _ := result.Consume(ctx)
528528
// return &neo4j.EagerResult{
529529
// Keys: keys,
530-
// Records: records,
530+
// Rows: records,
531531
// Summary: summary,
532532
// }, nil
533533
// })

neo4j/driver_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,10 @@ func (sum *fakeSummary) Profile() ProfiledPlan {
967967
panic("implement me")
968968
}
969969

970+
func (sum *fakeSummary) QueryProfile() QueryProfile {
971+
panic("implement me")
972+
}
973+
970974
func (sum *fakeSummary) Notifications() []Notification {
971975
panic("implement me")
972976
}

neo4j/internal/bolt/bolt3.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func (b *bolt3) discardStream(ctx context.Context) error {
424424
}
425425

426426
var (
427-
sum *db.Summary
427+
sum *idb.Summary
428428
err error
429429
)
430430
for sum == nil && err == nil {
@@ -442,7 +442,7 @@ func (b *bolt3) bufferStream(ctx context.Context) error {
442442

443443
n := 0
444444
var (
445-
sum *db.Summary
445+
sum *idb.Summary
446446
err error
447447
rec *db.Record
448448
)
@@ -552,7 +552,7 @@ func (b *bolt3) Keys(streamHandle idb.StreamHandle) ([]string, error) {
552552

553553
// Reads one record from the stream.
554554
func (b *bolt3) Next(ctx context.Context, streamHandle idb.StreamHandle) (
555-
*db.Record, *db.Summary, error) {
555+
*db.Record, *idb.Summary, error) {
556556
stream, ok := streamHandle.(*stream)
557557
if !ok {
558558
return nil, nil, errors.New("invalid stream handle")
@@ -574,7 +574,7 @@ func (b *bolt3) Next(ctx context.Context, streamHandle idb.StreamHandle) (
574574
}
575575

576576
func (b *bolt3) Consume(ctx context.Context, streamHandle idb.StreamHandle) (
577-
*db.Summary, error) {
577+
*idb.Summary, error) {
578578
stream, ok := streamHandle.(*stream)
579579
if !ok {
580580
return nil, errors.New("invalid stream handle")
@@ -618,7 +618,7 @@ func (b *bolt3) Buffer(ctx context.Context,
618618
}
619619

620620
// Reads one record from the network.
621-
func (b *bolt3) receiveNext(ctx context.Context) (*db.Record, *db.Summary, error) {
621+
func (b *bolt3) receiveNext(ctx context.Context) (*db.Record, *idb.Summary, error) {
622622
if err := b.assertState(bolt3_streaming, bolt3_streamingtx); err != nil {
623623
return nil, nil, err
624624
}
@@ -859,8 +859,8 @@ func (b *bolt3) ReAuth(ctx context.Context, auth *idb.ReAuthToken) error {
859859
return nil
860860
}
861861

862-
func (b *bolt3) Version() db.ProtocolVersion {
863-
return db.ProtocolVersion{
862+
func (b *bolt3) Version() idb.ProtocolVersion {
863+
return idb.ProtocolVersion{
864864
Major: 3,
865865
Minor: b.minor,
866866
}

neo4j/internal/bolt/bolt4.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ func (b *bolt4) Keys(streamHandle idb.StreamHandle) ([]string, error) {
666666

667667
// Next reads one record from the stream.
668668
func (b *bolt4) Next(ctx context.Context, streamHandle idb.StreamHandle) (
669-
*db.Record, *db.Summary, error) {
669+
*db.Record, *idb.Summary, error) {
670670
// Do NOT set b.err for this error
671671
stream, err := b.streams.getUnsafe(streamHandle)
672672
if err != nil {
@@ -699,7 +699,7 @@ func (b *bolt4) Next(ctx context.Context, streamHandle idb.StreamHandle) (
699699
}
700700

701701
func (b *bolt4) Consume(ctx context.Context, streamHandle idb.StreamHandle) (
702-
*db.Summary, error) {
702+
*idb.Summary, error) {
703703
// Do NOT set b.err for this error
704704
stream, err := b.streams.getUnsafe(streamHandle)
705705
if err != nil {
@@ -972,8 +972,8 @@ func (b *bolt4) ReAuth(ctx context.Context, auth *idb.ReAuthToken) error {
972972
return nil
973973
}
974974

975-
func (b *bolt4) Version() db.ProtocolVersion {
976-
return db.ProtocolVersion{
975+
func (b *bolt4) Version() idb.ProtocolVersion {
976+
return idb.ProtocolVersion{
977977
Major: 4,
978978
Minor: b.minor,
979979
}
@@ -1193,7 +1193,7 @@ func (b *bolt4) initializeReadTimeoutHint(hints map[string]any) {
11931193
b.queue.in.connReadTimeout = time.Duration(readTimeout) * time.Second
11941194
}
11951195

1196-
func (b *bolt4) extractSummary(success *success, stream *stream) *db.Summary {
1196+
func (b *bolt4) extractSummary(success *success, stream *stream) *idb.Summary {
11971197
summary := success.summary()
11981198
summary.Agent = b.serverVersion
11991199
summary.Major = 4

neo4j/internal/bolt/bolt5.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type internalTx5 struct {
6565
notificationConfig idb.NotificationConfig
6666
}
6767

68-
func (i *internalTx5) toMeta(logger log.Logger, logId string, version db.ProtocolVersion) map[string]any {
68+
func (i *internalTx5) toMeta(logger log.Logger, logId string, version idb.ProtocolVersion) map[string]any {
6969
if i == nil {
7070
return nil
7171
}
@@ -662,7 +662,7 @@ func (b *bolt5) Keys(streamHandle idb.StreamHandle) ([]string, error) {
662662

663663
// Next reads one record from the stream.
664664
func (b *bolt5) Next(ctx context.Context, streamHandle idb.StreamHandle) (
665-
*db.Record, *db.Summary, error) {
665+
*db.Record, *idb.Summary, error) {
666666
// Do NOT set b.err for this error
667667
stream, err := b.streams.getUnsafe(streamHandle)
668668
if err != nil {
@@ -695,7 +695,7 @@ func (b *bolt5) Next(ctx context.Context, streamHandle idb.StreamHandle) (
695695
}
696696

697697
func (b *bolt5) Consume(ctx context.Context, streamHandle idb.StreamHandle) (
698-
*db.Summary, error) {
698+
*idb.Summary, error) {
699699
// Do NOT set b.err for this error
700700
stream, err := b.streams.getUnsafe(streamHandle)
701701
if err != nil {
@@ -964,8 +964,8 @@ func (b *bolt5) Database() string {
964964
return b.databaseName
965965
}
966966

967-
func (b *bolt5) Version() db.ProtocolVersion {
968-
return db.ProtocolVersion{
967+
func (b *bolt5) Version() idb.ProtocolVersion {
968+
return idb.ProtocolVersion{
969969
Major: 5,
970970
Minor: b.minor,
971971
}
@@ -1232,7 +1232,7 @@ func (b *bolt5) initializeSsrEnabledHint(hints map[string]any) {
12321232
b.ssrEnabled = ssrEnabled
12331233
}
12341234

1235-
func (b *bolt5) extractSummary(success *success, stream *stream) *db.Summary {
1235+
func (b *bolt5) extractSummary(success *success, stream *stream) *idb.Summary {
12361236
summary := success.summary()
12371237
summary.Agent = b.serverVersion
12381238
summary.Major = 5

neo4j/internal/bolt/bolt5_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ func TestBolt5(outer *testing.T) {
19391939
for _, test := range txTimeoutTestCases {
19401940
outer.Run(test.description, func(t *testing.T) {
19411941
tx := internalTx5{timeout: test.input}
1942-
version := db.ProtocolVersion{Major: 5, Minor: 0}
1942+
version := idb.ProtocolVersion{Major: 5, Minor: 0}
19431943
actual, ok := tx.toMeta(logger, "", version)["tx_timeout"]
19441944
if test.omitted {
19451945
if ok {

neo4j/internal/bolt/bolt6.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type internalTx6 struct {
6060
notificationConfig idb.NotificationConfig
6161
}
6262

63-
func (i *internalTx6) toMeta(logger log.Logger, logId string, version db.ProtocolVersion) map[string]any {
63+
func (i *internalTx6) toMeta(logger log.Logger, logId string, version idb.ProtocolVersion) map[string]any {
6464
if i == nil {
6565
return nil
6666
}
@@ -658,7 +658,7 @@ func (b *bolt6) Keys(streamHandle idb.StreamHandle) ([]string, error) {
658658

659659
// Next reads one record from the stream.
660660
func (b *bolt6) Next(ctx context.Context, streamHandle idb.StreamHandle) (
661-
*db.Record, *db.Summary, error) {
661+
*db.Record, *idb.Summary, error) {
662662
// Do NOT set b.err for this error
663663
stream, err := b.streams.getUnsafe(streamHandle)
664664
if err != nil {
@@ -691,7 +691,7 @@ func (b *bolt6) Next(ctx context.Context, streamHandle idb.StreamHandle) (
691691
}
692692

693693
func (b *bolt6) Consume(ctx context.Context, streamHandle idb.StreamHandle) (
694-
*db.Summary, error) {
694+
*idb.Summary, error) {
695695
// Do NOT set b.err for this error
696696
stream, err := b.streams.getUnsafe(streamHandle)
697697
if err != nil {
@@ -933,8 +933,8 @@ func (b *bolt6) Database() string {
933933
return b.databaseName
934934
}
935935

936-
func (b *bolt6) Version() db.ProtocolVersion {
937-
return db.ProtocolVersion{
936+
func (b *bolt6) Version() idb.ProtocolVersion {
937+
return idb.ProtocolVersion{
938938
Major: 6,
939939
Minor: b.minor,
940940
}
@@ -1201,7 +1201,7 @@ func (b *bolt6) initializeSsrEnabledHint(hints map[string]any) {
12011201
b.ssrEnabled = ssrEnabled
12021202
}
12031203

1204-
func (b *bolt6) extractSummary(success *success, stream *stream) *db.Summary {
1204+
func (b *bolt6) extractSummary(success *success, stream *stream) *idb.Summary {
12051205
summary := success.summary()
12061206
summary.Agent = b.serverVersion
12071207
summary.Major = 6

neo4j/internal/bolt/bolt6_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ func TestBolt6(outer *testing.T) {
17181718
for _, test := range txTimeoutTestCases {
17191719
outer.Run(test.description, func(t *testing.T) {
17201720
tx := internalTx6{timeout: test.input}
1721-
version := db.ProtocolVersion{Major: 6, Minor: 0}
1721+
version := idb.ProtocolVersion{Major: 6, Minor: 0}
17221722
actual, ok := tx.toMeta(logger, "", version)["tx_timeout"]
17231723
if test.omitted {
17241724
if ok {

0 commit comments

Comments
 (0)