Skip to content

Commit

Permalink
Add segment to instrumentation, fixes #1640, fixes #1344 (#1696)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Jul 15, 2019
1 parent 93ea28d commit e8ec25f
Show file tree
Hide file tree
Showing 67 changed files with 3,618 additions and 132 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -30,7 +30,7 @@ PKG := github.com/drud/ddev
SRC_DIRS := cmd pkg

# Version variables to replace in build
VERSION_VARIABLES ?= DdevVersion SentryDSN
VERSION_VARIABLES ?= DdevVersion SentryDSN SegmentKey

# These variables will be used as the default unless overridden by the make
DdevVersion ?= $(VERSION)
Expand Down
30 changes: 21 additions & 9 deletions cmd/ddev/cmd/root.go
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/drud/ddev/pkg/ddevapp"
"github.com/drud/ddev/pkg/dockerutil"
"github.com/drud/ddev/pkg/globalconfig"
"github.com/drud/ddev/pkg/nodeps"
Expand Down Expand Up @@ -101,7 +102,7 @@ Support: https://ddev.readthedocs.io/en/stable/#support`,
if _, ok := ignores[cmd.CalledAs()]; ok {
return
}
sentryNotSetupWarning()
instrumentationNotSetUpWarning()

// All this nonsense is to capture the official usage we used for this command.
// Unfortunately cobra doesn't seem to provide this easily.
Expand All @@ -113,13 +114,21 @@ Support: https://ddev.readthedocs.io/en/stable/#support`,
fullCommand = append(fullCommand, util.GetFirstWord(cmdCopy.Parent().Use))
cmdCopy = cmdCopy.Parent()
}
uString := "Usage:"
for i := len(fullCommand) - 1; i >= 0; i = i - 1 {
uString = uString + " " + fullCommand[i]
for i := 0; i < len(fullCommand)/2; i++ {
j := len(fullCommand) - i - 1
fullCommand[i], fullCommand[j] = fullCommand[j], fullCommand[i]
}

if globalconfig.DdevGlobalConfig.InstrumentationOptIn && version.SentryDSN != "" && nodeps.IsInternetActive() {
_ = raven.CaptureMessageAndWait(uString, map[string]string{"severity-level": "info", "report-type": "usage"})
uString := strings.Join(fullCommand, " ")
event := ""
if len(fullCommand) > 1 {
event = fullCommand[1]
}

instrumentationNotSetUpWarning()
if globalconfig.DdevGlobalConfig.InstrumentationOptIn && version.SentryDSN != "" && nodeps.IsInternetActive() && len(fullCommand) > 1 {
_ = raven.CaptureMessageAndWait("Usage: "+uString, map[string]string{"severity-level": "info", "report-type": "usage"})
ddevapp.SendInstrumentationEvents(event)
}
},
}
Expand Down Expand Up @@ -151,16 +160,19 @@ func init() {
}
}

func sentryNotSetupWarning() {
func instrumentationNotSetUpWarning() {
if version.SentryDSN == "" && globalconfig.DdevGlobalConfig.InstrumentationOptIn {
output.UserOut.Warning("Instrumentation is opted in, but SentryDSN is not available.")
}
if version.SegmentKey == "" && globalconfig.DdevGlobalConfig.InstrumentationOptIn {
output.UserOut.Warning("Instrumentation is opted in, but SegmentKey is not available.")
}
}

// checkDdevVersionAndOptInSentry() reads global config and checks to see if current version is different
// checkDdevVersionAndOptInInstrumentation() reads global config and checks to see if current version is different
// from the last saved version. If it is, prompt to request anon ddev usage stats
// and update the info.
func checkDdevVersionAndOptInSentry() error {
func checkDdevVersionAndOptInInstrumentation() error {
if !output.JSONOutput && version.COMMIT != globalconfig.DdevGlobalConfig.LastUsedVersion && globalconfig.DdevGlobalConfig.InstrumentationOptIn == false && !globalconfig.DdevNoSentry {
allowStats := util.Confirm("It looks like you have a new ddev release.\nMay we send anonymous ddev usage statistics and errors?\nTo know what we will see please take a look at\nhttps://ddev.readthedocs.io/en/latest/users/cli-usage/#opt-in-usage-information\nPermission to beam up?")
if allowStats {
Expand Down
3 changes: 1 addition & 2 deletions cmd/ddev/cmd/sequelpro.go
Expand Up @@ -10,7 +10,6 @@ import (

"runtime"

"github.com/drud/ddev/pkg/appports"
"github.com/drud/ddev/pkg/ddevapp"
"github.com/drud/ddev/pkg/dockerutil"
"github.com/drud/ddev/pkg/output"
Expand Down Expand Up @@ -57,7 +56,7 @@ func handleSequelProCommand(appLocation string) (string, error) {
return "", err
}

dbPrivatePort, err := strconv.ParseInt(appports.GetPort("db"), 10, 64)
dbPrivatePort, err := strconv.ParseInt(ddevapp.GetPort("db"), 10, 64)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ddev/cmd/start.go
Expand Up @@ -31,7 +31,7 @@ any directory by running 'ddev start projectname [projectname ...]'`,
}

// Look for version change and opt-in Sentry if it has changed.
err = checkDdevVersionAndOptInSentry()
err = checkDdevVersionAndOptInInstrumentation()
if err != nil {
util.Failed(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ddev/main.go
Expand Up @@ -15,6 +15,6 @@ func main() {
func init() {
if !globalconfig.DdevNoSentry {
_ = raven.SetDSN(version.SentryDSN)
ddevapp.SetRavenBaseTags()
ddevapp.SetInstrumentationBaseTags()
}
}
6 changes: 6 additions & 0 deletions go.mod
Expand Up @@ -6,8 +6,10 @@ require (
github.com/Masterminds/sprig v2.15.0+incompatible
github.com/aokoli/goutils v1.0.1 // indirect
github.com/aws/aws-sdk-go v1.14.31
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/certifi/gocertifi v0.0.0-20180905225744-ee1a9a0726d2 // indirect
github.com/cheggaaa/pb v1.0.25
github.com/denisbrodbeck/machineid v1.0.1
github.com/drud/go-pantheon v0.1.0
github.com/evalphobia/logrus_sentry v0.5.0
github.com/fatih/color v1.7.0
Expand All @@ -24,6 +26,7 @@ require (
github.com/imdario/mergo v0.3.5 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jtolds/gls v4.2.1+incompatible // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/lextoumbourou/goodhosts v2.1.0+incompatible
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a
github.com/magiconair/properties v1.8.0 // indirect
Expand All @@ -36,6 +39,7 @@ require (
github.com/onsi/gomega v1.4.3 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pkg/errors v0.8.0
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c // indirect
github.com/sirupsen/logrus v1.0.6
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
Expand All @@ -46,9 +50,11 @@ require (
github.com/spf13/pflag v1.0.1 // indirect
github.com/spf13/viper v1.0.2
github.com/stretchr/testify v1.2.2
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac
gopkg.in/cheggaaa/pb.v1 v1.0.26 // indirect
gopkg.in/ini.v1 v1.39.0 // indirect
gopkg.in/segmentio/analytics-go.v3 v3.0.1
gopkg.in/yaml.v2 v2.2.1
gotest.tools v2.2.0+incompatible // indirect
)
15 changes: 15 additions & 0 deletions go.sum
Expand Up @@ -14,6 +14,8 @@ github.com/aokoli/goutils v1.0.1 h1:7fpzNGoJ3VA8qcrm++XEE1QUe0mIwNeLa02Nwq7RDkg=
github.com/aokoli/goutils v1.0.1/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ=
github.com/aws/aws-sdk-go v1.14.31 h1:amhorvKh1zNxo9YCntvA5uDmgw+pCYXOp4xO8WS1oDg=
github.com/aws/aws-sdk-go v1.14.31/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/certifi/gocertifi v0.0.0-20180905225744-ee1a9a0726d2 h1:MmeatFT1pTPSVb4nkPmBFN/LRZ97vPjsFKsZrU3KKTs=
github.com/certifi/gocertifi v0.0.0-20180905225744-ee1a9a0726d2/go.mod h1:GJKEexRPVJrBSOjoqN5VNOIKJ5Q3RViH6eu3puDRwx4=
github.com/cheggaaa/pb v1.0.25 h1:tFpebHTkI7QZx1q1rWGOKhbunhZ3fMaxTvHDWn1bH/4=
Expand All @@ -22,6 +24,8 @@ github.com/containerd/continuity v0.0.0-20180814194400-c7c5070e6f6e h1:KEBqsIJcj
github.com/containerd/continuity v0.0.0-20180814194400-c7c5070e6f6e/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
github.com/docker/docker v0.7.3-0.20180827131323-0c5f8d2b9b23 h1:mJtkfC9RUrUWHMk0cFDNhVoc9U3k2FRAzEZ+5pqSIHo=
github.com/docker/docker v0.7.3-0.20180827131323-0c5f8d2b9b23/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
Expand Down Expand Up @@ -77,6 +81,11 @@ github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Ao
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lextoumbourou/goodhosts v2.1.0+incompatible h1:1U1p5Z1wrXl23/fW/GY4zdTbQ8UJbyvrkPbqAZ6tzbw=
github.com/lextoumbourou/goodhosts v2.1.0+incompatible/go.mod h1:89s48k108X3gKDWn8AHk3gUzUGTcMZCCAOsE4QU1bbo=
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw=
Expand Down Expand Up @@ -111,6 +120,8 @@ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c h1:rsRTAcCR5CeNLkvgBVSjQoDGRRt6kggsE6XYBqCv2KQ=
github.com/segmentio/backo-go v0.0.0-20160424052352-204274ad699c/go.mod h1:kJ9mm9YmoWSkk+oQ+5Cj8DEoRCX2JT6As4kEtIIOp1M=
github.com/sirupsen/logrus v1.0.6 h1:hcP1GmhGigz/O7h1WVUM5KklBp1JoNS9FggWKdj/j3s=
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
Expand All @@ -135,6 +146,8 @@ github.com/vishvananda/netlink v1.0.0 h1:bqNY2lgheFIu1meHUFSH3d7vG93AFyqg3oGbJCO
github.com/vishvananda/netlink v1.0.0/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc h1:R83G5ikgLMxrBvLh22JhdfI8K6YXEPHx5P03Uu3DRs4=
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c h1:3lbZUMbMiGUW/LMkfsEABsc5zNT9+b1CvsJx47JzJ8g=
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM=
golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac h1:7d7lG9fHOLdL6jZPtnV4LpI41SbohIJ1Atq7U991dMg=
golang.org/x/crypto v0.0.0-20180820150726-614d502a4dac/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -159,6 +172,8 @@ gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNj
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
gopkg.in/ini.v1 v1.39.0 h1:Jf2sFGT+sAd7i+4ftUN1Jz90uw8XNH8NXbbOY16taA8=
gopkg.in/ini.v1 v1.39.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/segmentio/analytics-go.v3 v3.0.1 h1:lPX/m/RnUFwu33p/1vRx4O3aexmrS6vB8OkIiXnPgAw=
gopkg.in/segmentio/analytics-go.v3 v3.0.1/go.mod h1:4QqqlTlSSpVlWA9/9nDcPw+FkM2yv1NQoYjUbL9/JAw=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
Expand Down
37 changes: 0 additions & 37 deletions pkg/appports/ports.go
@@ -1,40 +1,3 @@
package appports

import (
"strings"

"github.com/drud/ddev/pkg/util"
)

// Define the DBA and MailHog ports as variables so that we can override them with ldflags if required.

// DBAPort defines the default phpmyadmin port used on the router.
var dbaPort = "8036"

// mailHogPort defines the default mailhog exposed by the router.
var mailhogPort = "8025"

// dbPort defines the default DB (MySQL) port.
var dbPort = "3306"

// webPort defines the internal web port
var webPort = "80"

var ports = map[string]string{
"mailhog": mailhogPort,
"dba": dbaPort,
"db": dbPort,
"web": webPort,
}

// GetPort returns the external router (as a string) for the given service. This can be used to find a given port for docker-compose manifests,
// or for automated testing.
func GetPort(service string) string {
service = strings.ToLower(service)
val, ok := ports[service]
if !ok {
util.Failed("Could not find port for service %s", service)
}

return val
}
3 changes: 1 addition & 2 deletions pkg/ddevapp/backdrop.go
Expand Up @@ -9,7 +9,6 @@ import (

"io/ioutil"

"github.com/drud/ddev/pkg/appports"
"github.com/drud/ddev/pkg/archive"
"github.com/drud/ddev/pkg/fileutil"
"github.com/drud/ddev/pkg/output"
Expand Down Expand Up @@ -44,7 +43,7 @@ func NewBackdropSettings(app *DdevApp) *BackdropSettings {
DatabasePassword: "db",
DatabaseHost: "db",
DatabaseDriver: "mysql",
DatabasePort: appports.GetPort("db"),
DatabasePort: GetPort("db"),
DatabasePrefix: "",
HashSalt: util.RandString(64),
Signature: DdevFileSignature,
Expand Down
9 changes: 4 additions & 5 deletions pkg/ddevapp/config.go
Expand Up @@ -22,7 +22,6 @@ import (

"runtime"

"github.com/drud/ddev/pkg/appports"
"github.com/drud/ddev/pkg/fileutil"
"github.com/drud/ddev/pkg/output"
"github.com/drud/ddev/pkg/util"
Expand Down Expand Up @@ -133,7 +132,7 @@ func NewApp(AppRoot string, includeOverrides bool, provider string) (*DdevApp, e
} else {
return app, fmt.Errorf("provider '%s' is not implemented", provider)
}
app.SetRavenTags()
app.SetInstrumentationAppTags()
return app, nil
}

Expand Down Expand Up @@ -627,9 +626,9 @@ func (app *DdevApp) RenderComposeYAML() (string, error) {
Name: app.Name,
Plugin: "ddev",
AppType: app.Type,
MailhogPort: appports.GetPort("mailhog"),
DBAPort: appports.GetPort("dba"),
DBPort: appports.GetPort("db"),
MailhogPort: GetPort("mailhog"),
DBAPort: GetPort("dba"),
DBPort: GetPort("db"),
DdevGenerated: DdevFileSignature,
HostDockerInternalIP: hostDockerInternalIP,
ComposeVersion: version.DockerComposeFileFormatVersion,
Expand Down
5 changes: 2 additions & 3 deletions pkg/ddevapp/ddevapp.go
Expand Up @@ -23,7 +23,6 @@ import (
"time"

"github.com/drud/ddev/pkg/appimport"
"github.com/drud/ddev/pkg/appports"
"github.com/drud/ddev/pkg/archive"
"github.com/drud/ddev/pkg/ddevhosts"
"github.com/drud/ddev/pkg/dockerutil"
Expand Down Expand Up @@ -196,7 +195,7 @@ func (app *DdevApp) Describe() (map[string]interface{}, error) {
dbinfo["host"] = "db"
dbPublicPort, err := app.GetPublishedPort("db")
util.CheckErr(err)
dbinfo["dbPort"] = appports.GetPort("db")
dbinfo["dbPort"] = GetPort("db")
util.CheckErr(err)
dbinfo["published_port"] = dbPublicPort
dbinfo["mariadb_version"] = app.MariaDBVersion
Expand Down Expand Up @@ -238,7 +237,7 @@ func (app *DdevApp) GetPublishedPort(serviceName string) (int, error) {
return -1, fmt.Errorf("Failed to find container of type %s: %v", serviceName, err)
}

privatePort, _ := strconv.ParseInt(appports.GetPort(serviceName), 10, 16)
privatePort, _ := strconv.ParseInt(GetPort(serviceName), 10, 16)

publishedPort := dockerutil.GetPublishedPort(privatePort, *container)
return publishedPort, nil
Expand Down
3 changes: 1 addition & 2 deletions pkg/ddevapp/drupal.go
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/drud/ddev/pkg/dockerutil"

"github.com/drud/ddev/pkg/appports"
"github.com/drud/ddev/pkg/output"
"github.com/drud/ddev/pkg/util"

Expand Down Expand Up @@ -51,7 +50,7 @@ func NewDrupalSettings(app *DdevApp) *DrupalSettings {
DatabasePassword: "db",
DatabaseHost: "db",
DatabaseDriver: "mysql",
DatabasePort: appports.GetPort("db"),
DatabasePort: GetPort("db"),
DatabasePrefix: "",
HashSalt: util.RandString(64),
Signature: DdevFileSignature,
Expand Down

0 comments on commit e8ec25f

Please sign in to comment.