Skip to content

Commit 0412430

Browse files
committed
Fix sysinfo: in 5.0 settings metrics.namespaces.enabled is removed
and always true
1 parent fe4a79a commit 0412430

File tree

5 files changed

+118
-21
lines changed

5 files changed

+118
-21
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2002-2021 "Neo4j,"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
21+
describe(':sysinfo command', () => {
22+
before(function () {
23+
cy.visit(Cypress.config('url')).title().should('include', 'Neo4j Browser')
24+
cy.wait(3000)
25+
cy.ensureConnection()
26+
})
27+
beforeEach(() => {
28+
cy.executeCommand(':clear')
29+
})
30+
31+
if (Cypress.config('serverVersion') >= 4.0) {
32+
it('sysinfo shows store size', () => {
33+
cy.executeCommand(':sysinfo')
34+
35+
cy.get('[data-testid="Database"]').should('not.have.text', '-')
36+
})
37+
}
38+
39+
it('sysinfo shows Id allocation', () => {
40+
cy.executeCommand(
41+
'CREATE (a:TestLabel)-[:CONNECTS]->(b:TestLabel) RETURN a, b'
42+
)
43+
44+
cy.executeCommand(':sysinfo')
45+
46+
cy.get('[data-testid="Relationship Type ID"]').should('not.have.text', '-')
47+
48+
// Clear
49+
cy.executeCommand('MATCH (a:TestLabel) DETACH DELETE a')
50+
})
51+
})

src/browser/components/Tables.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ export const SysInfoTableEntry = ({
109109
return mappedValue || !optional ? (
110110
<StyledTr>
111111
<StyledTdKey>{label}</StyledTdKey>
112-
<StyledTd>{mappedValue || missingValuePlaceholder}</StyledTd>
112+
<StyledTd data-testid={label}>
113+
{mappedValue || missingValuePlaceholder}
114+
</StyledTd>
113115
</StyledTr>
114116
) : null
115117
}

src/shared/modules/dbMeta/dbMetaDuck.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export const initialClientSettings: ClientSettings = {
116116
retainEditorHistory: false, // default is true, but set to false until settings read
117117
allowTelemetry: true, // default is true. Renamed to client.allow_telemetry after 5.0
118118
authEnabled: true, // default is true
119-
metricsNamespacesEnabled: false, // default is false, Renamed to server.metrics.namespaces.enabled after 5.0
119+
metricsNamespacesEnabled: false, // pre 5.0: default is false, from and after 5.0: settings removed, always true
120120
metricsPrefix: 'neo4j' // default is 'neo4j', Renamed to server.metrics.prefix after 5.0
121121
}
122122
// Initial state

src/shared/modules/dbMeta/dbMetaEpics.test.ts

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import { cleanupSettings } from './dbMetaEpics'
2222
import { ClientSettings } from './dbMetaDuck'
23+
import { SemVer } from 'semver'
2324

2425
const defaultSettings: ClientSettings = {
2526
allowOutgoingConnections: true,
@@ -30,7 +31,7 @@ const defaultSettings: ClientSettings = {
3031
retainEditorHistory: true,
3132
allowTelemetry: true,
3233
authEnabled: true,
33-
metricsNamespacesEnabled: false,
34+
metricsNamespacesEnabled: true,
3435
metricsPrefix: 'neo4j'
3536
}
3637

@@ -58,60 +59,94 @@ describe('cleanupSettings', () => {
5859
retainEditorHistory: true,
5960
allowTelemetry: true,
6061
authEnabled: true,
61-
metricsNamespacesEnabled: false,
62+
metricsNamespacesEnabled: true,
6263
metricsPrefix: 'neo4j4j'
6364
}
6465

65-
const newSettings = cleanupSettings(rawSettings)
66+
const newSettings = cleanupSettings(rawSettings, null)
6667

6768
expect(newSettings).toEqual(expectedSettings)
6869
})
6970
test('default values', () => {
70-
const newSettings = cleanupSettings({})
71+
const newSettings = cleanupSettings({}, null)
7172
expect(newSettings).toEqual(defaultSettings)
7273
})
7374
test('browser.allow_outgoing_connections="false"', () => {
74-
const newSettings = cleanupSettings({
75-
'browser.allow_outgoing_connections': 'false'
76-
})
75+
const newSettings = cleanupSettings(
76+
{
77+
'browser.allow_outgoing_connections': 'false'
78+
},
79+
null
80+
)
7781
const expectedSettings = {
7882
...defaultSettings,
7983
allowOutgoingConnections: false
8084
}
8185
expect(newSettings).toEqual(expectedSettings)
8286
})
8387
test('browser.allow_outgoing_connections="true"', () => {
84-
const newSettings = cleanupSettings({
85-
'browser.allow_outgoing_connections': 'true'
86-
})
88+
const newSettings = cleanupSettings(
89+
{
90+
'browser.allow_outgoing_connections': 'true'
91+
},
92+
null
93+
)
8794
const expectedSettings: ClientSettings = {
8895
...defaultSettings,
8996
allowOutgoingConnections: true
9097
}
9198
expect(newSettings).toEqual(expectedSettings)
9299
})
93100
test('clients.allow_telemetry="false"', () => {
94-
const newSettings = cleanupSettings({ 'clients.allow_telemetry': 'false' })
101+
const newSettings = cleanupSettings(
102+
{ 'clients.allow_telemetry': 'false' },
103+
null
104+
)
95105
const expectedSettings: ClientSettings = {
96106
...defaultSettings,
97107
allowTelemetry: false
98108
}
99109
expect(newSettings).toEqual(expectedSettings)
100110
})
101111
test('client.allow_telemetry="false"', () => {
102-
const newSettings = cleanupSettings({ 'client.allow_telemetry': 'false' })
112+
const newSettings = cleanupSettings(
113+
{ 'client.allow_telemetry': 'false' },
114+
null
115+
)
103116
const expectedSettings: ClientSettings = {
104117
...defaultSettings,
105118
allowTelemetry: false
106119
}
107120
expect(newSettings).toEqual(expectedSettings)
108121
})
109122
test('server.metrics.prefix=""', () => {
110-
const newSettings = cleanupSettings({ 'server.metrics.prefix': '' })
123+
const newSettings = cleanupSettings({ 'server.metrics.prefix': '' }, null)
111124
const expectedSettings: ClientSettings = {
112125
...defaultSettings,
113126
metricsPrefix: ''
114127
}
115128
expect(newSettings).toEqual(expectedSettings)
116129
})
130+
test('metricsNamespacesEnabled should be default false in 4.0', () => {
131+
const newSettings = cleanupSettings(
132+
{ 'server.metrics.namespaces.enabled': '' },
133+
new SemVer('4.0.0')
134+
)
135+
const expectedSettings: ClientSettings = {
136+
...defaultSettings,
137+
metricsNamespacesEnabled: false
138+
}
139+
expect(newSettings).toEqual(expectedSettings)
140+
})
141+
test('metricsNamespacesEnabled should be default true in 5.0', () => {
142+
const newSettings = cleanupSettings(
143+
{ 'server.metrics.namespaces.enabled': '' },
144+
new SemVer('5.0.0')
145+
)
146+
const expectedSettings: ClientSettings = {
147+
...defaultSettings,
148+
metricsNamespacesEnabled: true
149+
}
150+
expect(newSettings).toEqual(expectedSettings)
151+
})
117152
})

src/shared/modules/dbMeta/dbMetaEpics.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import {
7979
getListProcedureQuery
8080
} from '../cypher/functionsAndProceduresHelper'
8181
import { isInt, Record } from 'neo4j-driver'
82-
import { gte } from 'semver'
82+
import semver, { gte, SemVer } from 'semver'
8383
import { triggerCredentialsTimeout } from '../credentialsPolicy/credentialsPolicyDuck'
8484

8585
async function databaseList(store: any) {
@@ -390,13 +390,18 @@ export const serverConfigEpic = (some$: any, store: any) =>
390390
.do((res: any) => {
391391
if (!res) return Rx.Observable.of(null)
392392

393+
const neo4jVersion = getSemanticVersion(store.getState())
394+
393395
const rawSettings = res.records.reduce((all: any, record: any) => {
394396
const name = record.get('name')
395397
all[name] = record.get('value')
396398
return all
397399
}, {})
398400

399-
const settings: ClientSettings = cleanupSettings(rawSettings)
401+
const settings: ClientSettings = cleanupSettings(
402+
rawSettings,
403+
neo4jVersion
404+
)
400405

401406
// side-effects
402407
store.dispatch(
@@ -419,7 +424,10 @@ export const serverConfigEpic = (some$: any, store: any) =>
419424
.do(() => store.dispatch(update({ serverConfigDone: true })))
420425
.mapTo({ type: 'SERVER_CONFIG_DONE' })
421426

422-
export const cleanupSettings = (rawSettings: any) => {
427+
export const cleanupSettings = (
428+
rawSettings: any,
429+
neo4jVersion: SemVer | null
430+
) => {
423431
const settings: ClientSettings = {
424432
allowOutgoingConnections: !isConfigValFalsy(
425433
rawSettings['browser.allow_outgoing_connections']
@@ -441,10 +449,11 @@ export const cleanupSettings = (rawSettings: any) => {
441449
isConfigValFalsy(rawSettings['client.allow_telemetry'])
442450
), // default true
443451
authEnabled: !isConfigValFalsy(rawSettings['dbms.security.auth_enabled']), // default true
444-
// Info: metrics... in versions < 5.0, server.metrics... in versions >= 5.0
452+
// Info: in versions < 5.0 exists and defaults to false, in versions >= 5.0 is removed and always true
445453
metricsNamespacesEnabled:
446-
isConfigValTruthy(rawSettings['metrics.namespaces.enabled']) ||
447-
isConfigValTruthy(rawSettings['server.metrics.namespaces.enabled']), // default false
454+
neo4jVersion && semver.satisfies(neo4jVersion, '<5.0.0')
455+
? isConfigValTruthy(rawSettings['metrics.namespaces.enabled'])
456+
: true,
448457
metricsPrefix:
449458
rawSettings['metrics.prefix'] ??
450459
rawSettings['server.metrics.prefix'] ??

0 commit comments

Comments
 (0)