Skip to content

Commit

Permalink
[#3668] Store rack install & rack update telemetry data (V2)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriadams committed May 3, 2023
1 parent ae6e5f5 commit 1b1a540
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 2 deletions.
7 changes: 7 additions & 0 deletions provider/aws/formation/rack.json
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,12 @@
"Description": "VPC CIDR Block",
"Type": "String"
},
"Telemetry": {
"AllowedValues": [ "true", "false" ],
"Default": "false",
"Description": "Activate telemetry data tracking.",
"Type": "String"
},
"Tenancy": {
"Type": "String",
"Description": "Dedicated Hardware",
Expand Down Expand Up @@ -3220,6 +3226,7 @@
"rack.SyslogDestination": { "Ref": "SyslogDestination" },
"rack.SyslogFormat": { "Ref": "SyslogFormat" },
"rack.Version": { "Ref": "Version" },
"rack.Telemetry": { "Ref": "Telemetry" },
"rack.Vpc": { "Fn::If": [ "BlankExistingVpc",
{ "Ref": "Vpc" },
{ "Ref": "ExistingVpc" }
Expand Down
104 changes: 104 additions & 0 deletions provider/aws/telemetry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package aws

import (
"crypto/sha256"
"encoding/hex"
"strings"
)

var (
skipParams = strings.Join([]string{
"DefaultAmi",
"DefaultAmiArm",
"Telemetry",
}, ",")

redactedParams = strings.Join([]string{
"Ami",
"ApiCount",
"ApiCpu",
"ApiMonitorMemory",
"ApiRouter",
"ApiWebMemory",
"Autoscale",
"AvailabilityZones",
"BuildCpu",
"BuildImage",
"BuildInstance",
"BuildInstancePolicy",
"BuildMemory",
"BuildVolumeSize",
"ClientId",
"Development",
"EcsPollInterval",
"EncryptEbs",
"Encryption",
"ExistingVpc",
"HighAvailability",
"HttpProxy",
"ImagePullBehavior",
"IMDSHttpTokens",
"Internal",
"InternalOnly",
"InternalSuffix",
"InstanceBootCommand",
"InstanceRunCommand",
"InstanceType",
"InstanceUpdateBatchSize",
"InstancePolicy",
"InstanceSecurityGroup",
"BuildInstanceSecurityGroup",
"InternetGateway",
"Key",
"LogBucket",
"LogDriver",
"LogRetention",
"Password",
"Private",
"PrivateApi",
"PrivateApiSecurityGroup",
"PrivateBuild",
"RouterInternalSecurityGroup",
"RouterSecurityGroup",
"ScheduleRackScaleDown",
"ScheduleRackScaleUp",
"SpotInstanceBid",
"SslPolicy",
"Subnet0CIDR",
"Subnet1CIDR",
"Subnet2CIDR",
"SubnetPrivate0CIDR",
"SubnetPrivate1CIDR",
"SubnetPrivate2CIDR",
"SwapSize",
"SyslogDestination",
"SyslogFormat",
"Version",
"VPCCIDR",
"Tenancy",
"WhiteList",
}, ",")
)

func (p *Provider) RackParamsToSync(params map[string]string) map[string]string {
toSync := make(map[string]string)
for k, v := range params {
if strings.Contains(skipParams, k) {
continue
}

if strings.Contains(redactedParams, k) {
v = hashParamValue(v)
}

toSync[k] = v
}

return toSync
}

func hashParamValue(value string) string {
hasher := sha256.New()
hasher.Write([]byte(value))
return hex.EncodeToString(hasher.Sum(nil))
}
28 changes: 26 additions & 2 deletions provider/aws/workers_heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"time"

"github.com/convox/logger"
"github.com/convox/rack/pkg/helpers"
)

Expand All @@ -11,17 +12,21 @@ func (p *Provider) workerHeartbeat() {
}

func (p *Provider) heartbeat() {
var log = logger.New("ns=workers.heartbeat")

s, err := p.SystemGet()
if err != nil {
log.Error(err)
return
}

as, err := p.AppList()
if err != nil {
log.Error(err)
return
}

p.Metrics.Post("heartbeat", map[string]interface{}{
ms := map[string]interface{}{
"id": coalesces(p.ClientId, p.StackId),
"app_count": len(as),
"instance_count": s.Count,
Expand All @@ -30,5 +35,24 @@ func (p *Provider) heartbeat() {
"rack_id": p.StackId,
"region": p.Region,
"version": s.Version,
})
}

telemetryOn := true
_, ok := s.Parameters["Telemetry"]
if ok {
if s.Parameters["Telemetry"] != "false" {
telemetryOn = false
}
}

if telemetryOn {
params := p.RackParamsToSync(s.Parameters)
log.Logf("Rack Params: %v", params)
ms["rack_params"] = params
}

if err := p.Metrics.Post("heartbeat", ms); err != nil {
log.Error(err)
return
}
}

0 comments on commit 1b1a540

Please sign in to comment.