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

Feature/#2439 prefect server telemetry #2467

Merged
merged 13 commits into from
May 12, 2020
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ These changes are available in the [release/0.11.0 branch](https://github.com/Pr
### Server

- Add "cancellation-lite" semantic by preventing task runs from running if the flow run isn't running - [#2535](https://github.com/PrefectHQ/prefect/pull/2535)
- Add minimal telemetry to Prefect Server [#2467](https://github.com/PrefectHQ/prefect/pull/2467)

### Task Library

- Tasks to create issues for Jira and Jira Service Desk [#2431](https://github.com/PrefectHQ/prefect/pull/2431)

### Fixes

- Fix bug in Kubernetes agent ``deployment.yaml`` with a misconfigured liveness probe - [#2519](https://github.com/PrefectHQ/prefect/pull/2519)
- Fix bug in Kubernetes agent `deployment.yaml` with a misconfigured liveness probe - [#2519](https://github.com/PrefectHQ/prefect/pull/2519)

### Deprecations

Expand Down
9 changes: 7 additions & 2 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const sidebar98 = require('../api/0.9.8/sidebar')
const glob = require('glob')

// function for loading all MD files in a directory
const getChildren = function (parent_path, dir) {
const getChildren = function(parent_path, dir) {
return glob
.sync(parent_path + '/' + dir + '/**/*.md')
.map((path) => {
.map(path => {
// remove "parent_path" and ".md"
path = path.slice(parent_path.length + 1, -3)
// remove README
Expand Down Expand Up @@ -224,6 +224,11 @@ module.exports = {
'recipes/k8s_docker_sidecar'
]
},
{
title: 'Server',
collapsable: true,
children: ['server/telemetry']
},
{
title: 'FAQ',
collapsable: true,
Expand Down
18 changes: 18 additions & 0 deletions docs/orchestration/server/telemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Telemetry

Prefect Server sends usage telemetry and statistics to Prefect Technologies, Inc. All information collected is anonymous. We use this information to better understand how Prefect Server is used and to ensure that we're supporting active versions.

To opt-out of telemetry, add the following to your user configuration file (see [user configuration](../../core/concepts/configuration.md#user-configuration)).

```toml
[server.telemetry]
enabled = false
```

As an environment variable this would be:

```bash
export PREFECT_SERVER__TELEMETRY__ENABLED=false
```

See [configuration](../../core/concepts/configuration.md) for more details.
1 change: 1 addition & 0 deletions server/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ services:
HASURA_API_URL: ${HASURA_API_URL:-http://hasura:3000/v1alpha1/graphql}
PREFECT_API_URL: ${PREFECT_API_URL:-http://graphql:4201/graphql/}
PREFECT_API_HEALTH_URL: ${PREFECT_API_HEALTH_URL:-http://graphql:4201/health}
PREFECT_SERVER__TELEMETRY__ENABLED: ${PREFECT_SERVER__TELEMETRY__ENABLED:-true}
networks:
- prefect-server
restart: "always"
Expand Down
40 changes: 37 additions & 3 deletions server/services/apollo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/services/apollo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"graphql-depth-limit": "^1.1.0",
"graphql-tools": "^3.0.4",
"jsonwebtoken": "^8.5.1",
"node-fetch": "^2.3.0"
"node-fetch": "^2.3.0",
"uuid": "^8.0.0"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
Expand Down
38 changes: 38 additions & 0 deletions server/services/apollo/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
FilterRootFields
} from 'apollo-server'
import { HttpLink } from 'apollo-link-http'
import { v4 as uuidv4 } from 'uuid'

const APOLLO_API_PORT = process.env.APOLLO_API_PORT || '4200'
const APOLLO_API_BIND_ADDRESS = process.env.APOLLO_API_BIND_ADDRESS || '0.0.0.0'
Expand All @@ -23,6 +24,12 @@ const PREFECT_API_URL =
const PREFECT_API_HEALTH_URL =
process.env.PREFECT_API_HEALTH_URL || 'http://localhost:4201/health'

const PREFECT_SERVER__TELEMETRY__ENABLED =
process.env.PREFECT_SERVER__TELEMETRY__ENABLED || 'false'
// Convert from a TOML boolean to a JavaScript boolean
const TELEMETRY_ENABLED =
PREFECT_SERVER__TELEMETRY__ENABLED == 'true' ? true : false
const TELEMETRY_ID = uuidv4()
// --------------------------------------------------------------------
// Server
const depthLimit = require('graphql-depth-limit')
Expand Down Expand Up @@ -162,6 +169,12 @@ function sleep(ms) {
async function runServerForever() {
try {
await runServer()
send_telemetry_event('startup')
if (TELEMETRY_ENABLED) {
setInterval(() => {
send_telemetry_event('heartbeat')
}, 600000) // send heartbeat every 10 minutes
}
} catch (e) {
log(e, e.message, e.stack)
log('\nTrying again in 3 seconds...\n')
Expand All @@ -170,4 +183,29 @@ async function runServerForever() {
}
}

async function send_telemetry_event(event) {
if (TELEMETRY_ENABLED) {
try {
// TODO add timeout
const body = JSON.stringify({
source: 'prefect_server',
type: event,
payload: { id: TELEMETRY_ID }
})
log(`Sending telemetry to Prefect Technnologies, Inc: ${body}`)

fetch('https://sens-o-matic.prefect.io/', {
method: 'post',
body,
headers: {
'Content-Type': 'application/json',
'X-Prefect-Event': 'prefect_server-0.0.1'
}
})
} catch (error) {
log(`Error sending telemetry event: ${error.message}`)
}
}
}

runServerForever()
1 change: 1 addition & 0 deletions src/prefect/cli/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ services:
HASURA_API_URL: ${HASURA_API_URL:-http://hasura:3000/v1alpha1/graphql}
PREFECT_API_URL: ${PREFECT_API_URL:-http://graphql:4201/graphql/}
PREFECT_API_HEALTH_URL: ${PREFECT_API_HEALTH_URL:-http://graphql:4201/health}
PREFECT_SERVER__TELEMETRY__ENABLED: ${PREFECT_SERVER__TELEMETRY__ENABLED:-true}
networks:
- prefect-server
restart: "always"
Expand Down
3 changes: 3 additions & 0 deletions src/prefect/cli/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def make_env(fname=None):
port=config.server.graphql.port
),
APOLLO_HOST_PORT=config.server.host_port,
PREFECT_SERVER__TELEMETRY__ENABLED=(
"true" if config.server.telemetry.enabled is True else "false"
),
)

POSTGRES_ENV = dict(
Expand Down
3 changes: 3 additions & 0 deletions src/prefect/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ endpoint = "${server.host}:${server.port}"
endpoint = "${server.ui.host}:${server.ui.port}"
graphql_url = "http://localhost:4200/graphql"

[server.telemetry]
enabled = true

[cloud]
api = "${${backend}.endpoint}"
endpoint = "https://api.prefect.io"
Expand Down