Skip to content

Commit

Permalink
Fix typo phpmyadmin_http_url -> phpmyadmin_https_url, add WSL detecti…
Browse files Browse the repository at this point in the history
…on and database type (#2238)

* Fix typo phpmyadmin_http_url -> phpmyadmin_https_url
* Simplify SetInstrumentationAppTags and add more to TestSetInstrumentationAppTags
* Add database_type
* Add detection for WSL
  • Loading branch information
rfay committed May 9, 2020
1 parent b5a57ea commit 0b6e3ce
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
11 changes: 11 additions & 0 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ func (app *DdevApp) Describe() (map[string]interface{}, error) {
appDesc["httpsURLs"] = httpsURLs
appDesc["urls"] = allURLs

if app.MySQLVersion != "" {
appDesc["database_type"] = "mysql"
appDesc["mysql_version"] = app.MySQLVersion
} else {
appDesc["database_type"] = "mariadb" // default
appDesc["mariadb_version"] = app.MariaDBVersion
if app.MariaDBVersion == "" {
appDesc["mariadb_version"] = version.MariaDBDefaultVersion
}
}

// Only show extended status for running sites.
if app.SiteStatus() == SiteRunning {
if !nodeps.ArrayContainsString(app.GetOmittedContainers(), "db") {
Expand Down
16 changes: 13 additions & 3 deletions pkg/ddevapp/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"runtime"
"strconv"
"strings"
"time"
)

Expand All @@ -37,6 +38,13 @@ func SetInstrumentationBaseTags() {
isToolbox := nodeps.IsDockerToolbox()

nodeps.InstrumentationTags["OS"] = runtime.GOOS
if runtime.GOOS == "linux" {
wslDistro := os.Getenv("WSL_DISTRO_NAME")
if wslDistro != "" {
nodeps.InstrumentationTags["isWSL"] = "true"
nodeps.InstrumentationTags["wslDistro"] = wslDistro
}
}
nodeps.InstrumentationTags["dockerVersion"] = dockerVersion
nodeps.InstrumentationTags["dockerComposeVersion"] = composeVersion
nodeps.InstrumentationTags["dockerToolbox"] = strconv.FormatBool(isToolbox)
Expand All @@ -55,13 +63,15 @@ func getProjectHash(projectName string) string {

// SetInstrumentationAppTags creates app-specific tags for Segment
func (app *DdevApp) SetInstrumentationAppTags() {
ignoredProperties := []string{"approot", "hostname", "hostnames", "httpurl", "httpsurl", "httpURLs", "httpsURLs", "primary_url", "mailhog_url", "mailhog_https_url", "name", "phpmyadmin_url", "phpmyadmin_http_url", "router_status_log", "shortroot", "urls"}
ignoredProperties := []string{"approot", "hostname", "hostnames", "name", "router_status_log", "shortroot"}

describeTags, _ := app.Describe()
for key, val := range describeTags {
if !nodeps.ArrayContainsString(ignoredProperties, key) {
nodeps.InstrumentationTags[key] = fmt.Sprintf("%v", val)
// Make sure none of the "URL" attributes or the ignoredProperties comes through
if strings.Contains(strings.ToLower(key), "url") || nodeps.ArrayContainsString(ignoredProperties, key) {
continue
}
nodeps.InstrumentationTags[key] = fmt.Sprintf("%v", val)
}
nodeps.InstrumentationTags["ProjectID"] = getProjectHash(app.Name)
}
Expand Down
48 changes: 48 additions & 0 deletions pkg/ddevapp/instrumentation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ddevapp_test

import (
"fmt"
"github.com/drud/ddev/pkg/ddevapp"
"github.com/drud/ddev/pkg/nodeps"
"github.com/drud/ddev/pkg/testcommon"
"github.com/drud/ddev/pkg/util"
asrt "github.com/stretchr/testify/assert"
"strings"
"testing"
"time"
)

//TestSetInstrumentationAppTags checks to see that tags are properly set
//and tries to make sure no leakage happens with URLs or other
//tags that we don't want to see.
func TestSetInstrumentationAppTags(t *testing.T) {
assert := asrt.New(t)

site := TestSites[0]
runTime := util.TimeTrack(time.Now(), fmt.Sprintf("%s %s", site.Name, t.Name()))

testcommon.ClearDockerEnv()
app := new(ddevapp.DdevApp)

err := app.Init(site.Dir)
assert.NoError(err)
t.Cleanup(func() {
_ = app.Stop(true, false)
})
app.SetInstrumentationAppTags()

// Make sure that none of the "url" items in app.desc are being reported
for k := range nodeps.InstrumentationTags {
assert.NotContains(strings.ToLower(k), "url")
}

for _, unwanted := range []string{"approot", "hostname", "hostnames", "name", "router_status_log", "shortroot"} {
assert.Empty(nodeps.InstrumentationTags[unwanted])
}

// Make sure that expected attributes come through
for _, wanted := range []string{"database_type", "dbimg", "dbaimg", "nfs_mount_enabled", "ProjectID", "php_version", "router_http_port", "router_https_port", "router_status", "ssh_agent_status", "status", "type", "webimg", "webserver_type"} {
assert.NotEmpty(nodeps.InstrumentationTags[wanted], "tag '%s' was not found and it should have been", wanted)
}
runTime()
}

0 comments on commit 0b6e3ce

Please sign in to comment.