forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Source available metrics (mattermost#24879)
* Expose metrics under a source available license * do not assume Cluster() * allow metrics if licensed or dev * temporary vet override * simplify BULID_TAGS handling * auto clean old imports.go * fix license listener * e2e test metrics & license semantics * update from enterprise * switch back to mattermost-govet/v2@new now * update metrics from upstream * Update license_spec.js Co-authored-by: Saturnino Abril <[email protected]> * Update license_spec.js Co-authored-by: Saturnino Abril <[email protected]> * Update e2e-tests/cypress/tests/integration/channels/enterprise/metrics/license_spec.js Co-authored-by: Saturnino Abril <[email protected]> * Update e2e-tests/cypress/tests/integration/channels/enterprise/metrics/license_spec.js * split up specs * require/delete license earlier in e2e test * expanded expect to debug failures * more logging * Revert "more logging" This reverts commit 0bc513f. * e2e: try deleting license first * update from enterprise * toggleMetricsOn to work around license delete * eslint * ensure admin before deleting license * update from enterprise * updates from enterprise * fix cypress logging * temp: log at DEBUG for Cypress tests --------- Co-authored-by: Saturnino Abril <[email protected]> Co-authored-by: Mattermost Build <[email protected]>
- Loading branch information
1 parent
6184c36
commit b05093d
Showing
22 changed files
with
1,984 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
server/enterprise/LICENSE |
37 changes: 37 additions & 0 deletions
37
e2e-tests/cypress/tests/integration/channels/enterprise/metrics/helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
export const checkMetrics = (expectedStatusCode) => { | ||
cy.apiGetConfig().then(({config}) => { | ||
const baseURL = new URL(Cypress.config('baseUrl')); | ||
baseURL.port = config.MetricsSettings.ListenAddress.replace(/^.*:/, ''); | ||
baseURL.pathname = '/metrics'; | ||
|
||
cy.log({name: 'Metrics License', message: `Checking metrics at ${baseURL.toString()}`}); | ||
cy.request({ | ||
headers: {'X-Requested-With': 'XMLHttpRequest'}, | ||
url: baseURL.toString(), | ||
method: 'GET', | ||
failOnStatusCode: false, | ||
}).then((response) => { | ||
expect(response.headers['Content-Type'], 'should not hit webapp').not.to.equal('text/html'); | ||
expect(response.status, 'should match expected status code').to.equal(expectedStatusCode); | ||
}); | ||
}); | ||
}; | ||
|
||
// toggleMetricsOn turns metrics off and back on, forcing it to be tested against the current | ||
// license. When, in the future, the product detects license removal and does this automatically, | ||
// this helper won't be required. | ||
export const toggleMetricsOn = () => { | ||
cy.apiUpdateConfig({ | ||
MetricsSettings: { | ||
Enable: false, | ||
}, | ||
}); | ||
cy.apiUpdateConfig({ | ||
MetricsSettings: { | ||
Enable: true, | ||
}, | ||
}); | ||
}; |
44 changes: 44 additions & 0 deletions
44
e2e-tests/cypress/tests/integration/channels/enterprise/metrics/license_no_license_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
// *************************************************************** | ||
// - [#] indicates a test step (e.g. # Go to a page) | ||
// - [*] indicates an assertion (e.g. * Check the title) | ||
// - Use element ID when selecting an element. Create one if none. | ||
// *************************************************************** | ||
|
||
// Stage: @prod | ||
// Group: @channels @enterprise @metrics @not_cloud @license_removal | ||
|
||
import {checkMetrics, toggleMetricsOn} from './helper'; | ||
|
||
describe('Metrics > No license', () => { | ||
before(() => { | ||
cy.shouldNotRunOnCloudEdition(); | ||
cy.apiAdminLogin(); | ||
cy.apiDeleteLicense(); | ||
toggleMetricsOn(); | ||
}); | ||
|
||
it('should enable metrics in BUILD_NUMBER == dev environments', () => { | ||
cy.apiGetConfig(true).then(({config}) => { | ||
if (config.BuildNumber !== 'dev') { | ||
Cypress.log({name: 'Metrics License', message: `Skipping test since BUILD_NUMBER = ${config.BuildNumber}`}); | ||
return; | ||
} | ||
|
||
checkMetrics(200); | ||
}); | ||
}); | ||
|
||
it('should disable metrics in BUILD_NUMBER != dev environments', () => { | ||
cy.apiGetConfig(true).then(({config}) => { | ||
if (config.BuildNumber === 'dev') { | ||
Cypress.log({name: 'Metrics License', message: `Skipping test since BUILD_NUMBER = ${config.BuildNumber}`}); | ||
return; | ||
} | ||
|
||
checkMetrics(404); | ||
}); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
e2e-tests/cypress/tests/integration/channels/enterprise/metrics/license_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
// *************************************************************** | ||
// - [#] indicates a test step (e.g. # Go to a page) | ||
// - [*] indicates an assertion (e.g. * Check the title) | ||
// - Use element ID when selecting an element. Create one if none. | ||
// *************************************************************** | ||
|
||
// Stage: @prod | ||
// Group: @channels @enterprise @metrics @not_cloud | ||
|
||
import {checkMetrics, toggleMetricsOn} from './helper'; | ||
|
||
describe('Metrics > License', () => { | ||
before(() => { | ||
cy.shouldNotRunOnCloudEdition(); | ||
cy.apiRequireLicense(); | ||
toggleMetricsOn(); | ||
}); | ||
|
||
it('should enable metrics in BUILD_NUMBER == dev environments', () => { | ||
cy.apiGetConfig(true).then(({config}) => { | ||
if (config.BuildNumber !== 'dev') { | ||
Cypress.log({name: 'Metrics License', message: `Skipping test since BUILD_NUMBER = ${config.BuildNumber}`}); | ||
return; | ||
} | ||
|
||
checkMetrics(200); | ||
}); | ||
}); | ||
|
||
it('should enable metrics in BUILD_NUMBER != dev environments', () => { | ||
cy.apiGetConfig(true).then(({config}) => { | ||
if (config.BuildNumber === 'dev') { | ||
Cypress.log({name: 'Metrics License', message: `Skipping test since BUILD_NUMBER = ${config.BuildNumber}`}); | ||
return; | ||
} | ||
|
||
checkMetrics(200); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.