diff --git a/packages/strapi-telemetry/.gitignore b/packages/strapi-telemetry/.gitignore deleted file mode 100644 index 28ca81d44a..0000000000 --- a/packages/strapi-telemetry/.gitignore +++ /dev/null @@ -1,96 +0,0 @@ -############################ -# OS X -############################ - -.DS_Store -.AppleDouble -.LSOverride -Icon -.Spotlight-V100 -.Trashes -._* - - -############################ -# Linux -############################ - -*~ - - -############################ -# Windows -############################ - -Thumbs.db -ehthumbs.db -Desktop.ini -$RECYCLE.BIN/ -*.cab -*.msi -*.msm -*.msp - - -############################ -# Packages -############################ - -*.7z -*.csv -*.dat -*.dmg -*.gz -*.iso -*.jar -*.rar -*.tar -*.zip -*.com -*.class -*.dll -*.exe -*.o -*.seed -*.so -*.swo -*.swp -*.swn -*.swm -*.out -*.pid - - -############################ -# Logs and databases -############################ - -.tmp -*.log -*.sql -*.sqlite - - -############################ -# Misc. -############################ - -*# -.idea -nbproject - - -############################ -# Node.js -############################ - -lib-cov -lcov.info -pids -logs -results -build -node_modules -.node_history -package-lock.json - diff --git a/packages/strapi-telemetry/LICENSE.md b/packages/strapi-telemetry/LICENSE.md deleted file mode 100644 index b682ae0e8e..0000000000 --- a/packages/strapi-telemetry/LICENSE.md +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (c) 2015-2020 Strapi Solutions. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/strapi-telemetry/package.json b/packages/strapi-telemetry/package.json deleted file mode 100644 index 26f98189d2..0000000000 --- a/packages/strapi-telemetry/package.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "strapi-telemetry", - "version": "3.0.0-beta.19.3", - "description": "Strapi telemetry", - "keywords": [ - "telemetry" - ], - "homepage": "http://strapi.io", - "bugs": { - "url": "https://github.com/strapi/strapi/issues" - }, - "repository": { - "type": "git", - "url": "git://github.com/strapi/strapi.git", - "directory": "packages/strapi-telemetry" - }, - "license": "MIT", - "main": "lib/index.js", - "files": [ - "lib" - ], - "dependencies": { - "ci-info": "2.0.0", - "is-docker": "2.0.0", - "node-fetch": "2.6.0", - "node-machine-id": "1.1.12", - "node-schedule": "1.3.2" - }, - "engines": { - "node": ">=10.0.0", - "npm": ">=6.0.0" - } -} diff --git a/packages/strapi/lib/Strapi.js b/packages/strapi/lib/Strapi.js index 2d1434bfc5..e2a344fc48 100644 --- a/packages/strapi/lib/Strapi.js +++ b/packages/strapi/lib/Strapi.js @@ -7,9 +7,10 @@ const fse = require('fs-extra'); const Koa = require('koa'); const Router = require('koa-router'); const _ = require('lodash'); -const { logger, models } = require('strapi-utils'); const chalk = require('chalk'); const CLITable = require('cli-table3'); +const { logger, models } = require('strapi-utils'); +const { createDatabaseManager } = require('strapi-database'); const utils = require('./utils'); const loadModules = require('./core/load-modules'); @@ -18,15 +19,13 @@ const initializeMiddlewares = require('./middlewares'); const initializeHooks = require('./hooks'); const createStrapiFs = require('./core/fs'); const getPrefixedDeps = require('./utils/get-prefixed-dependencies'); - const createEventHub = require('./services/event-hub'); const createWebhookRunner = require('./services/webhook-runner'); const { webhookModel, createWebhookStore } = require('./services/webhook-store'); const { createCoreStore, coreStoreModel } = require('./services/core-store'); const createEntityService = require('./services/entity-service'); const createEntityValidator = require('./services/entity-validator'); -const { createDatabaseManager } = require('strapi-database'); -const createStrapiTelemetry = require('strapi-telemetry'); +const createTelemetry = require('./services/metrics'); const CONFIG_PATHS = { admin: 'admin', @@ -348,9 +347,7 @@ class Strapi { entityValidator: this.entityValidator, }); - this.telemetry = createStrapiTelemetry(this); - this.telemetry.initPing(); - this.app.use(this.telemetry.middleware); + this.telemetry = createTelemetry(this); // Initialize hooks and middlewares. await initializeMiddlewares.call(this); diff --git a/packages/strapi-telemetry/lib/index.js b/packages/strapi/lib/services/metrics/index.js similarity index 92% rename from packages/strapi-telemetry/lib/index.js rename to packages/strapi/lib/services/metrics/index.js index a2509dc251..69310273e4 100644 --- a/packages/strapi-telemetry/lib/index.js +++ b/packages/strapi/lib/services/metrics/index.js @@ -58,18 +58,13 @@ const createTelemetryInstance = strapi => { } }; - const initPing = () => { - if (isDisabled) { - return; - } - + if (!isDisabled) { scheduleJob('0 0 12 * * *', () => sendEvent('ping')); - }; + strapi.app.use(createMiddleware({ sendEvent })); + } return { - initPing, send: sendEvent, - middleware: createMiddleware({ sendEvent, isDisabled }), }; }; diff --git a/packages/strapi-telemetry/lib/middleware.js b/packages/strapi/lib/services/metrics/middleware.js similarity index 86% rename from packages/strapi-telemetry/lib/middleware.js rename to packages/strapi/lib/services/metrics/middleware.js index 3e114db9d4..f80d132178 100644 --- a/packages/strapi-telemetry/lib/middleware.js +++ b/packages/strapi/lib/services/metrics/middleware.js @@ -1,16 +1,12 @@ 'use strict'; -const createMiddleware = ({ sendEvent, isDisabled }) => { +const createMiddleware = ({ sendEvent }) => { const _state = { currentDay: null, counter: 0, }; return async (ctx, next) => { - if (isDisabled) { - return next(); - } - const { url, method } = ctx.request; if (!url.includes('.') && ['GET', 'PUT', 'POST', 'DELETE'].includes(method)) { diff --git a/packages/strapi-telemetry/lib/truthy-var.js b/packages/strapi/lib/services/metrics/truthy-var.js similarity index 100% rename from packages/strapi-telemetry/lib/truthy-var.js rename to packages/strapi/lib/services/metrics/truthy-var.js diff --git a/packages/strapi/package.json b/packages/strapi/package.json index 029a1687ac..4b6df82bc2 100644 --- a/packages/strapi/package.json +++ b/packages/strapi/package.json @@ -17,6 +17,7 @@ "boom": "^7.3.0", "chalk": "^2.4.1", "chokidar": "3.3.1", + "ci-info": "2.0.0", "cli-table3": "^0.5.1", "commander": "^2.20.0", "cross-spawn": "^6.0.5", @@ -26,6 +27,7 @@ "fs-extra": "^7.0.0", "glob": "^7.1.2", "inquirer": "^6.2.1", + "is-docker": "2.0.0", "koa": "^2.8.0", "koa-body": "^4.1.0", "koa-compose": "^4.1.0", @@ -42,9 +44,9 @@ "koa-static": "^5.0.0", "lodash": "^4.17.5", "minimatch": "^3.0.4", - "node-fetch": "^1.7.3", - "node-machine-id": "^1.1.10", - "node-schedule": "^1.2.0", + "node-fetch": "2.6.0", + "node-machine-id": "1.1.12", + "node-schedule": "1.3.2", "opn": "^5.3.0", "ora": "^3.0.0", "resolve-cwd": "^3.0.0", diff --git a/yarn.lock b/yarn.lock index 173ebaf37a..42d3eea640 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12389,7 +12389,7 @@ node-releases@^1.1.49: dependencies: semver "^6.3.0" -node-schedule@1.3.2, node-schedule@^1.2.0: +node-schedule@1.3.2: version "1.3.2" resolved "https://registry.yarnpkg.com/node-schedule/-/node-schedule-1.3.2.tgz#d774b383e2a6f6ade59eecc62254aea07cd758cb" integrity sha512-GIND2pHMHiReSZSvS6dpZcDH7pGPGFfWBIEud6S00Q8zEIzAs9ommdyRK1ZbQt8y1LyZsJYZgPnyi7gpU2lcdw==