Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update neo4j-driver to 1.7 and send transaction metadata with Cypher queries #848

Merged
merged 7 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"include": [
"src/**/*"
],
"include": ["src/**/*"],
"compilerOptions": {
"target": "ES6",
"allowSyntheticDefaultImports": true,
"baseUrl": "src/",
"checkJs": false,
"paths": {
"src-root/*": ["*"],
"services/*": ["shared/services/*"],
"browser-services/*": ["browser/services/*"],
"shared/*": ["shared/*"],
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|html)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
"^neo4j-driver-alias$": "neo4j-driver",
"^browser-styles(.*)$": "<rootDir>/src/browser/styles$1",
"^browser-components(.*)$": "<rootDir>/src/browser/components$1",
"worker-loader": "<rootDir>/__mocks__/workerLoaderMock.js"
"worker-loader": "<rootDir>/__mocks__/workerLoaderMock.js",
"project-root(.*)$": "<rootDir>$1"
},
"modulePaths": [
"<rootDir>/src",
Expand Down Expand Up @@ -148,7 +148,7 @@
"firebase": "^4.3.0",
"isomorphic-fetch": "^2.2.1",
"jsonic": "^0.3.0",
"neo4j-driver": "^1.6.1",
"neo4j-driver": "^1.7.0",
"react": "^16.4.1",
"react-addons-pure-render-mixin": "^15.0.2",
"react-dnd": "^2.5.1",
Expand Down
2 changes: 1 addition & 1 deletion src/browser/modules/Stream/CypherFrame/AsciiView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/* global jest, describe, test, expect */
import React from 'react'
import { render, cleanup } from 'react-testing-library'
import { v1 as neo4j } from 'neo4j-driver-alias'
import { v1 as neo4j } from 'neo4j-driver'

import { AsciiView, AsciiStatusbar } from './AsciiView'

Expand Down
2 changes: 1 addition & 1 deletion src/browser/modules/Stream/CypherFrame/CodeView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/* global describe, test, expect */
import React from 'react'
import { render, cleanup } from 'react-testing-library'
import { v1 as neo4j } from 'neo4j-driver-alias'
import { v1 as neo4j } from 'neo4j-driver'

import { CodeView, CodeStatusbar } from './CodeView'

Expand Down
2 changes: 1 addition & 1 deletion src/browser/modules/Stream/CypherFrame/PlanView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/* global jest, describe, test, expect */
import React from 'react'
import { render, cleanup } from 'react-testing-library'
import { v1 as neo4j } from 'neo4j-driver-alias'
import { v1 as neo4j } from 'neo4j-driver'

import { PlanView, PlanStatusbar } from './PlanView'

Expand Down
2 changes: 1 addition & 1 deletion src/browser/modules/Stream/CypherFrame/TableView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import React, { Component } from 'react'
import { v4 } from 'uuid'
import { v1 as neo4j } from 'neo4j-driver-alias'
import { v1 as neo4j } from 'neo4j-driver'
import {
StyledStatsBar,
PaddedTableViewDiv,
Expand Down
2 changes: 1 addition & 1 deletion src/browser/modules/Stream/CypherFrame/TableView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import React from 'react'
import { render, cleanup } from 'react-testing-library'
import { v1 as neo4j } from 'neo4j-driver-alias'
import { v1 as neo4j } from 'neo4j-driver'

import { TableView, TableStatusbar, renderObject } from './TableView'

Expand Down
7 changes: 4 additions & 3 deletions src/browser/modules/Stream/CypherFrame/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

import bolt from 'services/bolt/bolt'
import { v1 as neo4j } from 'neo4j-driver-alias'
import { v1 as neo4j } from 'neo4j-driver'
import * as viewTypes from 'shared/modules/stream/frameViewTypes'
import {
recursivelyExtractGraphItems,
Expand Down Expand Up @@ -51,8 +51,9 @@ export function getBodyAndStatusBarMessages (result, maxRows) {
let updateMessages = bolt.retrieveFormattedUpdateStatistics(result)
let streamMessage =
result.records.length > 0
? `started streaming ${result.records
.length} records ${resultAvailableAfter} ms and completed ${totalTimeString} ${streamMessageTail}`
? `started streaming ${
result.records.length
} records ${resultAvailableAfter} ms and completed ${totalTimeString} ${streamMessageTail}`
: `completed ${totalTimeString} ${streamMessageTail}`

if (updateMessages && updateMessages.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/browser/modules/Stream/CypherFrame/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/* global describe, test, expect */
/* eslint-disable new-cap */
import { v1 as neo4j } from 'neo4j-driver-alias'
import { v1 as neo4j } from 'neo4j-driver'
import * as viewTypes from 'shared/modules/stream/frameViewTypes'
import {
resultHasNodes,
Expand Down
8 changes: 6 additions & 2 deletions src/browser/modules/Stream/Queries/QueriesFrame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class QueriesFrame extends Component {
['User', '8%'],
['Query', 'auto'],
['Params', '7%'],
['Meta', '8%'],
['Meta', 'auto'],
['Elapsed time', '95px'],
['Kill', '95px']
]
Expand All @@ -236,7 +236,11 @@ export class QueriesFrame extends Component {
<StyledTd key='params' width={tableHeaderSizes[3][1]}>
<Code>{JSON.stringify(query.parameters, null, 2)}</Code>
</StyledTd>
<StyledTd key='meta' width={tableHeaderSizes[4][1]}>
<StyledTd
key='meta'
title={JSON.stringify(query.metaData, null, 2)}
width={tableHeaderSizes[4][1]}
>
<Code>{JSON.stringify(query.metaData, null, 2)}</Code>
</StyledTd>
<StyledTd key='time' width={tableHeaderSizes[5][1]}>
Expand Down
3 changes: 2 additions & 1 deletion src/shared/modules/commands/commandsDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ describe('commandsDuck', () => {
node: {
color: '#000'
}
}
},
meta: {}
})
})
afterEach(() => {
Expand Down
6 changes: 4 additions & 2 deletions src/shared/modules/commands/helpers/cypher.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const handleCypherCommand = (
action,
put,
params = {},
shouldUseCypherThread = false
shouldUseCypherThread = false,
txMetadata = undefined
) => {
const paramsToNeo4jType = Object.keys(params).map(k => ({
[k]: applyGraphTypes(params[k])
Expand All @@ -38,7 +39,8 @@ export const handleCypherCommand = (
{
useCypherThread: shouldUseCypherThread,
requestId: action.requestId,
cancelable: true
cancelable: true,
...txMetadata
}
)
put(send('cypher', id))
Expand Down
9 changes: 8 additions & 1 deletion src/shared/modules/currentUser/currentUserDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
CONNECTION_SUCCESS,
DISCONNECTION_SUCCESS
} from 'shared/modules/connections/connectionsDuck'
import { getBackgroundTxMetadata } from 'shared/services/bolt/txMetadata'
import { canSendTxMetadata } from '../features/featuresDuck'

export const NAME = 'user'
export const UPDATE_CURRENT_USER = NAME + '/UPDATE_CURRENT_USER'
Expand Down Expand Up @@ -89,7 +91,12 @@ export const getCurrentUserEpic = (some$, store) =>
bolt.directTransaction(
'CALL dbms.security.showCurrentUser()',
{},
{ useCypherThread: shouldUseCypherThread(store.getState()) }
{
useCypherThread: shouldUseCypherThread(store.getState()),
...getBackgroundTxMetadata({
hasServerSupport: canSendTxMetadata(store.getState())
})
}
)
)
.catch(() => Rx.Observable.of(null))
Expand Down
55 changes: 33 additions & 22 deletions src/shared/modules/dbMeta/dbMetaDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
onLostConnection
} from 'shared/modules/connections/connectionsDuck'
import { shouldUseCypherThread } from 'shared/modules/settings/settingsDuck'
import { getBackgroundTxMetadata } from 'shared/services/bolt/txMetadata'
import { canSendTxMetadata } from '../features/featuresDuck'

export const NAME = 'meta'
export const UPDATE = 'meta/UPDATE'
Expand Down Expand Up @@ -65,7 +67,8 @@ export function getMetaInContext (state, context) {
}
}

export const getVersion = state => state[NAME].server.version
export const getVersion = state =>
(state[NAME] || {}).server ? (state[NAME] || {}).server.version : 0
export const getEdition = state => state[NAME].server.edition
export const getDbName = state => state[NAME].server.dbName
export const getStoreSize = state => state[NAME].server.storeSize
Expand Down Expand Up @@ -285,37 +288,45 @@ export const dbMetaEpic = (some$, store) =>
.merge(some$.ofType(CONNECTION_SUCCESS))
.mergeMap(() => {
return (
Rx.Observable
.timer(1, 20000)
Rx.Observable.timer(1, 20000)
.merge(some$.ofType(FORCE_FETCH))
// Labels, types and propertyKeys
.mergeMap(() =>
Rx.Observable
.fromPromise(
bolt.routedReadTransaction(
metaQuery,
{},
{
useCypherThread: shouldUseCypherThread(store.getState()),
onLostConnection: onLostConnection(store.dispatch)
}
)
Rx.Observable.fromPromise(
bolt.routedReadTransaction(
metaQuery,
{},
{
useCypherThread: shouldUseCypherThread(store.getState()),
onLostConnection: onLostConnection(store.dispatch),
...getBackgroundTxMetadata({
hasServerSupport: canSendTxMetadata(store.getState())
})
}
)
.catch(e => Rx.Observable.of(null))
).catch(e => {
return Rx.Observable.of(null)
})
)
.filter(r => r)
.do(res => store.dispatch(updateMeta(res)))
// Cluster role
.mergeMap(() =>
Rx.Observable
.fromPromise(
bolt.directTransaction(
'CALL dbms.cluster.role() YIELD role',
{},
{ useCypherThread: shouldUseCypherThread(store.getState()) }
)
Rx.Observable.fromPromise(
bolt.directTransaction(
'CALL dbms.cluster.role() YIELD role',
{},
{
useCypherThread: shouldUseCypherThread(store.getState()),
...getBackgroundTxMetadata({
hasServerSupport: canSendTxMetadata(store.getState())
})
}
)
.catch(e => Rx.Observable.of(null))
)
.catch(e => {
return Rx.Observable.of(null)
})
.do(res => {
if (!res) return Rx.Observable.of(null)
const role = res.records[0].get(0)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/modules/dbMeta/dbMetaDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

/* global describe, test, expect */
import { v1 as neo4j } from 'neo4j-driver-alias'
import { v1 as neo4j } from 'neo4j-driver'
import reducer, * as meta from './dbMetaDuck'
import { APP_START } from 'shared/modules/app/appDuck'

Expand Down
26 changes: 23 additions & 3 deletions src/shared/modules/features/featuresDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,36 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import semver from 'semver'
import Rx from 'rxjs/Rx'
import bolt from 'services/bolt/bolt'
import { APP_START, WEB } from 'shared/modules/app/appDuck'
import { CONNECTION_SUCCESS } from 'shared/modules/connections/connectionsDuck'
import { shouldUseCypherThread } from 'shared/modules/settings/settingsDuck'
import { getBackgroundTxMetadata } from 'shared/services/bolt/txMetadata'
import { getVersion } from '../dbMeta/dbMetaDuck'

export const NAME = 'features'
export const RESET = 'features/RESET'
export const UPDATE_ALL_FEATURES = 'features/UPDATE_ALL_FEATURES'
const NEO4J_TX_METADATA_VERSION = '3.5.0-alpha01'

export const getAvailableProcedures = state => state[NAME].availableProcedures
export const isACausalCluster = state =>
getAvailableProcedures(state).includes('dbms.cluster.overview')
export const canAssignRolesToUser = state =>
getAvailableProcedures(state).includes('dbms.security.addRoleToUser')
export const useBrowserSync = state => !!state[NAME].browserSync
export const canSendTxMetadata = state => {
const serverVersion = getVersion(state)
if (!serverVersion) {
return false
}
if (semver.gt(serverVersion, NEO4J_TX_METADATA_VERSION)) {
return true
}
return false
}

const initialState = {
availableProcedures: [],
Expand Down Expand Up @@ -70,16 +85,21 @@ export const featuresDiscoveryEpic = (action$, store) => {
.routedReadTransaction(
'CALL dbms.procedures YIELD name',
{},
{ useCypherThread: shouldUseCypherThread(store.getState()) }
{
useCypherThread: shouldUseCypherThread(store.getState()),
...getBackgroundTxMetadata({
hasServerSupport: canSendTxMetadata(store.getState())
})
}
)
.then(res => {
store.dispatch(
updateFeatures(res.records.map(record => record.get('name')))
)
return null
return Rx.Observable.of(null)
})
.catch(e => {
return null
return Rx.Observable.of(null)
})
})
.mapTo({ type: 'NOOP' })
Expand Down
Loading