Browse Source

more telemetry for sub services 1st draft

master
forest 1 month ago
parent
commit
9268842ca2
12 changed files with 77 additions and 47 deletions
  1. +1
    -1
      build-docker.sh
  2. +2
    -1
      frontend.go
  3. +1
    -0
      frontend/alpha-profile.gotemplate.html
  4. +22
    -11
      frontend/static/install.sh
  5. +6
    -1
      frontend/static/uninstall.sh
  6. +8
    -8
      frontend_login.go
  7. +1
    -1
      frontend_profile.go
  8. +8
    -8
      main.go
  9. +14
    -11
      scheduled_tasks.go
  10. +12
    -3
      telemetry.go
  11. +1
    -1
      threshold/src_remote_install.sh
  12. +1
    -1
      threshold_provisioning_service.go

+ 1
- 1
build-docker.sh View File

@ -1,6 +1,6 @@
#!/bin/bash -e
VERSION="0.0.25"
VERSION="0.0.27"
rm -rf dockerbuild || true
mkdir dockerbuild


+ 2
- 1
frontend.go View File

@ -15,6 +15,7 @@ import (
"path/filepath"
"regexp"
"runtime/debug"
"strconv"
"strings"
"sync"
"time"
@ -101,7 +102,7 @@ func initFrontend(workingDirectory string, config *Config, model *DBModel, backe
defer (func() {
if r := recover(); r != nil {
go postTelemetry("greenhouse-web", "", "admin", fmt.Sprintf("HomepageMarkdown poller panic: %s", r))
go postTelemetry("greenhouse-web", "", "admin", strconv.Itoa(config.AdminTenantId), fmt.Sprintf("HomepageMarkdown poller panic: %s", r))
fmt.Printf("HomepageMarkdown poller: panic: %+v\n", r)
debug.PrintStack()


+ 1
- 0
frontend/alpha-profile.gotemplate.html View File

@ -227,5 +227,6 @@
<div style="margin-left: 20px; margin-right: 20px;">
<h3>Telemetry Data for your account:</h3>
<p>This data is delayed by 5 minutes</p>
<pre class="telemetry">{{.LokiResponseString}}</pre>
</div>

+ 22
- 11
frontend/static/install.sh View File

@ -12,9 +12,18 @@ footer_with_url()
printf "See: https://greenhouse-alpha.server.garden/install-greenhouse-self-hosting-software-linux\n"
printf "\n"
}
# first order of business, decide which daemon_telemetry_id we are going to use.
daemon_telemetry_id="error_daemon_id_not_found"
if cat /opt/greenhouse-daemon/daemon-telemetry-id.txt > /dev/null 2>&1 ; then
daemon_telemetry_id="$(cat /opt/greenhouse-daemon/daemon-telemetry-id.txt)"
elif command -v "hexdump" > /dev/null 2>&1 ; then
daemon_telemetry_id="$(hexdump -n 4 -e '4/4 "%08X" 1 "\n"' /dev/urandom)"
fi
telemetry()
{
curl -sS -X POST -H "Content-Type: text/plain" "https://telemetry.greenhouse-alpha.server.garden/?type=$1&ip=auto" -d "$2"
curl -sS -X POST -H "Content-Type: text/plain" "https://telemetry.greenhouse-alpha.server.garden/?type=$1&ip=auto&daemon=$daemon_telemetry_id" -d "$2"
}
telemetry "install-start" "install.sh is running"
@ -109,13 +118,12 @@ check_command_exists()
fi
}
check_command_exists hexdump
check_command_exists curl
check_command_exists gzip
check_command_exists sha256sum
## at this point we have checked everything we need to check to ensure that the instal should go off without a hitch.
## next up are the functions related to installation, then the installation itself
@ -170,18 +178,21 @@ mkdir -p /opt/greenhouse-daemon
chown greenhouse-daemon:greenhouse-daemon /opt/greenhouse-daemon
chmod 700 /opt/greenhouse-daemon
daemon_version="alpha-rc0-315e67e-82d8"
threshold_version="0.0.0-6cfcabd-f27e"
printf "%s" "$daemon_telemetry_id" > /opt/greenhouse-daemon/daemon-telemetry-id.txt
chown greenhouse-daemon:greenhouse-daemon /opt/greenhouse-daemon/daemon-telemetry-id.txt
daemon_version="alpha-rc0-11b0f85-2440"
threshold_version="0.0.0-6cfcabd-dc60"
caddy_version="v2.4.0-beta.2-forest-078f12e0-b4a8"
cli_version="0.0.0-30860fd-b875"
daemon_amd64_sha256="7444a520cdd1f03c25e3b4b91cbdb8ceda8d413e670abcf64dafb8c767b8979f"
daemon_arm_sha256="d8b17fc791fe9a8b21b420a9168e4f90d5eee20f56a56df631ce12a39055d62c"
daemon_arm64_sha256="2c06031be3605bd320c3a933b80827e1b19ee76cdd45c2e47458eaa8ec14053e"
daemon_amd64_sha256="4da9ec8691f1c3a43a47546a99e02dbba1794223c540d23d3283760f514f62e1"
daemon_arm_sha256="53103af940c37ea7fd1bc0e29f56077954de317e76bacbd9951bff22d6286566"
daemon_arm64_sha256="cb425a130c4c6ebb9f285fe37d0597cf334e6f16ff081a8658f4aa3790ca6398"
threshold_amd64_sha256="dc064148c6cb386ecfabbbc1f9f0c4e162398cbc74b8e7138664f2876624da61"
threshold_arm_sha256="770a86253955483954cf35c023feeb7fc999bfeaff4b389c23dba718fdb10dd3"
threshold_arm64_sha256="3760d687eecbacc2a072f4d0cd99d8111390b1c731806262770adc2901d27d82"
threshold_amd64_sha256="e5685b43e0e2199047215e8b52a052b994c414ed724a94649ada917369408d01"
threshold_arm_sha256="aba131d89ae5d7a60dfa38d5ae8768bab4d0b60d59ba5ae9e71e564f4aadce5a"
threshold_arm64_sha256="c42fb11d6d4c9ed603ee644ad32afc899b1bbcdb512083874ef14195ada9ac50"
caddy_amd64_sha256="acfd32aa766b91c46bd9cefbdd8c3f6a6c4b0adb176968880b4bf214b1fce94b"
caddy_arm_sha256="833d00e2056befd25524d105352065299d1eac4274e190e2f31596533ee72cd9"


+ 6
- 1
frontend/static/uninstall.sh View File

@ -1,6 +1,11 @@
#!/bin/sh
curl -sS -X POST -H "Content-Type: text/plain" "https://telemetry.greenhouse-alpha.server.garden/?type=uninstall&ip=auto" -d "uninstall.sh is running..."
daemon_telemetry_id="error_daemon_id_not_found"
if cat /opt/greenhouse-daemon/daemon-telemetry-id.txt > /dev/null 2>&1 ; then
daemon_telemetry_id="$(cat /opt/greenhouse-daemon/daemon-telemetry-id.txt)"
fi
curl -sS -X POST -H "Content-Type: text/plain" "https://telemetry.greenhouse-alpha.server.garden/?type=uninstall&ip=auto&daemon=$daemon_telemetry_id" -d "uninstall.sh is running..."
systemctl stop greenhouse-daemon.service


+ 8
- 8
frontend_login.go View File

@ -58,7 +58,7 @@ func registerLoginRoutes(app *FrontendApp, emailService *EmailService) {
"JS HMAC Login: %t, loginSuccess: %t, emailVerified: %t, returnTo: %s",
remoteUsersHMAC != "", loginSuccess, emailVerified, returnTo,
)
go postTelemetry("login", getRemoteIpFromRequest(request), email, loginTelemetry)
go postTelemetry("login", getRemoteIpFromRequest(request), email, strconv.Itoa(tenantId), loginTelemetry)
if loginSuccess {
err := app.setSession(
@ -185,13 +185,13 @@ func registerLoginRoutes(app *FrontendApp, emailService *EmailService) {
"registration (JS HMAC: %t, tokenHash=%s) send email failed: %s",
hashedPassword != "", getHashForTelemetry(app, emailVerificationToken), (*session.Flash)["error"],
)
go postTelemetry("register", getRemoteIpFromRequest(request), data.Email, registerTelemetry)
go postTelemetry("register", getRemoteIpFromRequest(request), data.Email, strconv.Itoa(tenantId), registerTelemetry)
} else {
registerTelemetry := fmt.Sprintf(
"registration (JS HMAC: %t, tokenHash=%s) success!!",
hashedPassword != "", getHashForTelemetry(app, emailVerificationToken),
)
go postTelemetry("register", getRemoteIpFromRequest(request), data.Email, registerTelemetry)
go postTelemetry("register", getRemoteIpFromRequest(request), data.Email, strconv.Itoa(tenantId), registerTelemetry)
http.Redirect(responseWriter, request, "/verify-email", http.StatusFound)
return
@ -202,7 +202,7 @@ func registerLoginRoutes(app *FrontendApp, emailService *EmailService) {
"registration (JS HMAC: %t) not attempted because: %s",
hashedPassword != "", (*session.Flash)["error"],
)
go postTelemetry("register", getRemoteIpFromRequest(request), data.Email, registerTelemetry)
go postTelemetry("register", getRemoteIpFromRequest(request), data.Email, "", registerTelemetry)
}
}
app.buildPageFromTemplate(responseWriter, request, session, "register.html", data)
@ -286,7 +286,7 @@ func registerLoginRoutes(app *FrontendApp, emailService *EmailService) {
}
telemetryValue := fmt.Sprintf("POST id=%s name=%s", getHashForTelemetry(app, appAuthSessionId), name)
go postTelemetry("app-auth-session", getRemoteIpFromRequest(request), "", telemetryValue)
go postTelemetry("app-auth-session", getRemoteIpFromRequest(request), "", "", telemetryValue)
app.applicationAuthSessions[appAuthSessionId] = &ApplicationAuthSession{
Name: name,
@ -305,19 +305,19 @@ func registerLoginRoutes(app *FrontendApp, emailService *EmailService) {
}
telemetryValue = fmt.Sprintf("%s success!!", telemetryValue)
go postTelemetry("app-auth-session", getRemoteIpFromRequest(request), "", telemetryValue)
go postTelemetry("app-auth-session", getRemoteIpFromRequest(request), "", strconv.Itoa(appAuthSession.TenantId), telemetryValue)
responseWriter.Header().Set("Content-Type", "text/plain")
responseWriter.Write([]byte(apiToken))
} else {
telemetryValue = fmt.Sprintf("%s 401 unauthorized", telemetryValue)
go postTelemetry("app-auth-session", getRemoteIpFromRequest(request), "", telemetryValue)
go postTelemetry("app-auth-session", getRemoteIpFromRequest(request), "", strconv.Itoa(appAuthSession.TenantId), telemetryValue)
http.Error(responseWriter, "401 unauthorized", http.StatusUnauthorized)
}
} else {
telemetryValue = fmt.Sprintf("%s 404 not found", telemetryValue)
go postTelemetry("app-auth-session", getRemoteIpFromRequest(request), "", telemetryValue)
go postTelemetry("app-auth-session", getRemoteIpFromRequest(request), "", "", telemetryValue)
http.Error(responseWriter, "404 not found", http.StatusNotFound)
}


+ 1
- 1
frontend_profile.go View File

@ -455,7 +455,7 @@ func registerProfileRoutes(app *FrontendApp) {
}
func getTelemetryFromLokiForUser(app *FrontendApp, email string) string {
lokiQuery := fmt.Sprintf("{delay=\"rt\", account=~\"^%s$\"}", email)
lokiQuery := fmt.Sprintf("{delay=\"user\", account=~\"^%s$\"}", email)
lokiQueryURL := fmt.Sprintf(
"%s/loki/api/v1/query_range?direction=BACKWARD&limit=1000&query=%s&start=%d&end=%d&step=900",
app.LokiURL, url.QueryEscape(lokiQuery), time.Now().Add(-1*time.Hour*24*29).UnixNano(), time.Now().Add(time.Hour).UnixNano(),


+ 8
- 8
main.go View File

@ -55,7 +55,7 @@ const isProduction = false
func main() {
_, err := time.LoadLocation("UTC")
if err != nil {
go postTelemetry("greenhouse-web", "", "admin", fmt.Sprintf("load UTC location failed: %s", err))
go postTelemetry("greenhouse-web", "", "admin", "", fmt.Sprintf("load UTC location failed: %s", err))
panic(errors.Wrap(err, "can't start the app because can't load UTC location"))
}
@ -65,7 +65,7 @@ func main() {
emailService := &config.SMTP
err = emailService.Initialize()
if err != nil {
go postTelemetry("greenhouse-web", "", "admin", fmt.Sprintf("emailService.Initialize() failed: %s", err))
go postTelemetry("greenhouse-web", "", "admin", strconv.Itoa(config.AdminTenantId), fmt.Sprintf("emailService.Initialize() failed: %s", err))
panic(err)
}
@ -78,19 +78,19 @@ func main() {
frontendApp := initFrontend(workingDirectory, config, model, backendApp, emailService, ingressService)
scheduledTasks := NewScheduledTasks(ingressService, backendApp, model)
scheduledTasks := NewScheduledTasks(ingressService, backendApp, model, config.AdminTenantId)
err = scheduledTasks.Initialize()
if err != nil {
// TODO should this be Fatalf??
go postTelemetry("greenhouse-web", "", "admin", fmt.Sprintf("initialization process failed: %s", err))
go postTelemetry("greenhouse-web", "", "admin", strconv.Itoa(config.AdminTenantId), fmt.Sprintf("initialization process failed: %s", err))
log.Printf("Greenhouse's initialization process failed: \n%+v\n\n", err)
}
go (func(backendApp *BackendApp) {
defer (func() {
if r := recover(); r != nil {
go postTelemetry("greenhouse-web", "", "admin", fmt.Sprintf("metric collection panic: %s", r))
go postTelemetry("greenhouse-web", "", "admin", strconv.Itoa(config.AdminTenantId), fmt.Sprintf("metric collection panic: %s", r))
fmt.Printf("backendApp: panic: %+v\n", r)
debug.PrintStack()
@ -101,7 +101,7 @@ func main() {
err := backendApp.ConsumeMetrics()
if err != nil {
firstLineOfError := strings.Split(fmt.Sprintf("metric collection failed: %s", err), "\n")[0]
go postTelemetry("greenhouse-web", "", "admin", firstLineOfError)
go postTelemetry("greenhouse-web", "", "admin", strconv.Itoa(config.AdminTenantId), firstLineOfError)
log.Printf("metric collection failed: %+v\n", err)
}
time.Sleep(time.Second * 6)
@ -139,10 +139,10 @@ func main() {
// })()
}
go postTelemetry("greenhouse-web", "", "admin", "greenhouse started up!")
go postTelemetry("greenhouse-web", "", "admin", strconv.Itoa(config.AdminTenantId), "greenhouse started up!")
err = frontendApp.ListenAndServe()
go postTelemetry("greenhouse-web", "", "admin", fmt.Sprintf("frontendApp.ListenAndServe(): %s", err))
go postTelemetry("greenhouse-web", "", "admin", strconv.Itoa(config.AdminTenantId), fmt.Sprintf("frontendApp.ListenAndServe(): %s", err))
panic(err)
}


+ 14
- 11
scheduled_tasks.go View File

@ -4,28 +4,31 @@ import (
"fmt"
"log"
"runtime/debug"
"strconv"
"time"
errors "git.sequentialread.com/forest/pkg-errors"
)
type ScheduledTasks struct {
Backend *BackendApp
Ingress *IngressService
DB *DBModel
Registry map[string]ScheduledTask
Backend *BackendApp
Ingress *IngressService
DB *DBModel
AdminTenantId int
Registry map[string]ScheduledTask
}
type ScheduledTask struct {
Every time.Duration
Action func() error
}
func NewScheduledTasks(ingress *IngressService, backendApp *BackendApp, dbModel *DBModel) *ScheduledTasks {
func NewScheduledTasks(ingress *IngressService, backendApp *BackendApp, dbModel *DBModel, adminTenantId int) *ScheduledTasks {
return &ScheduledTasks{
Ingress: ingress,
Backend: backendApp,
DB: dbModel,
Registry: map[string]ScheduledTask{},
Ingress: ingress,
Backend: backendApp,
DB: dbModel,
AdminTenantId: adminTenantId,
Registry: map[string]ScheduledTask{},
}
}
@ -106,7 +109,7 @@ func (tasks *ScheduledTasks) Initialize() error {
go (func() {
defer (func() {
if r := recover(); r != nil {
go postTelemetry("greenhouse-web", "", "admin", fmt.Sprintf("scheduledTasks panic: %s", r))
go postTelemetry("greenhouse-web", "", "admin", strconv.Itoa(tasks.AdminTenantId), fmt.Sprintf("scheduledTasks panic: %s", r))
fmt.Printf("scheduledTasks panic: %+v\n", r)
debug.PrintStack()
@ -128,7 +131,7 @@ func (tasks *ScheduledTasks) Initialize() error {
go (func(name string, scheduledTask ScheduledTask) {
err := scheduledTask.Action()
if err != nil {
go postTelemetry("greenhouse-web", "", "admin", fmt.Sprintf("scheduledTask '%s' failed: %s\n", name, err))
go postTelemetry("greenhouse-web", "", "admin", strconv.Itoa(tasks.AdminTenantId), fmt.Sprintf("scheduledTask '%s' failed: %s\n", name, err))
log.Printf("scheduledTask (%s) Action() failed: %+v\n", name, err)
} else {
err := tasks.DB.ScheduledTaskCompleted(name)


+ 12
- 3
telemetry.go View File

@ -7,6 +7,7 @@ import (
"io/ioutil"
"log"
"net/http"
"strconv"
"time"
)
@ -23,22 +24,30 @@ func getTelemetryClient() *http.Client {
func postTelemetryFromRequest(tyype string, request *http.Request, app *FrontendApp, content string) {
account := ""
userId := ""
session, err := app.getSession(request, app.Domain)
if err == nil {
account = session.Email
userId = strconv.Itoa(session.TenantId)
}
postTelemetry(tyype, getRemoteIpFromRequest(request), account, content)
postTelemetry(tyype, getRemoteIpFromRequest(request), account, userId, content)
}
func postTelemetry(tyype string, ip string, account string, content string) {
func postTelemetry(tyype string, ip string, account string, userId string, content string) {
if ip != "" {
ip = fmt.Sprintf("&ip=%s", ip)
}
if account != "" {
account = fmt.Sprintf("&account=%s", account)
}
if userId == "0" {
userId = ""
}
if userId != "" {
userId = fmt.Sprintf("&userId=%s", userId)
}
response, err := getTelemetryClient().Post(
fmt.Sprintf("https://telemetry.greenhouse-alpha.server.garden/?type=%s%s%s", tyype, ip, account),
fmt.Sprintf("https://telemetry.greenhouse-alpha.server.garden/?type=%s%s%s%s", tyype, ip, account, userId),
"text/plain",
bytes.NewBufferString(content),
)


+ 1
- 1
threshold/src_remote_install.sh View File

@ -5,7 +5,7 @@ systemctl stop threshold
rm -f threshold
curl -sS "https://picopublish.sequentialread.com/files/threshold-0.0.0-6cfcabd-f445-linux-amd64.gz" > "./threshold.gz"
curl -sS "https://picopublish.sequentialread.com/files/threshold-0.0.0-6cfcabd-dc60-linux-amd64.gz" > "./threshold.gz"
gzip --stdout --decompress "threshold.gz" > "./threshold"


+ 1
- 1
threshold_provisioning_service.go View File

@ -299,7 +299,7 @@ WantedBy=multi-user.target
})
substitutions := map[string]string{
"ARTIFACT_URL": "https://picopublish.sequentialread.com/files/threshold-0.0.0-6cfcabd-f445-linux-amd64.gz",
"ARTIFACT_URL": "https://picopublish.sequentialread.com/files/threshold-0.0.0-6cfcabd-dc60-linux-amd64.gz",
"THRESHOLD_SHA256": "9e769e539adeff539ffeacd1a44968da0d43f04afcd6c3faaae90689533e8cca",
"THRESHOLD_DOMAIN": "greenhouse.server.garden",
"GREENHOUSE_MANAGEMENT_API_AUTH_CA": string(managementAPIAuthCABytes),


Loading…
Cancel
Save