forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry reporting through checkpoint
Will report builders/provisioner/post-processor types used per build, and whether or not the build passed. Will also report any panics we see. You may opt out of this reporting by setting the environment variable `CHECKPOINT_DISABLE`.
- Loading branch information
Showing
12 changed files
with
520 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package packer | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
checkpoint "github.com/hashicorp/go-checkpoint" | ||
packerVersion "github.com/hashicorp/packer/version" | ||
) | ||
|
||
const TelemetryVersion string = "beta/packer/4" | ||
const TelemetryPanicVersion string = "beta/packer_panic/4" | ||
|
||
var CheckpointReporter CheckpointTelemetry | ||
|
||
func init() { | ||
CheckpointReporter.startTime = time.Now().UTC() | ||
} | ||
|
||
type PackerReport struct { | ||
Spans []*TelemetrySpan `json:"spans"` | ||
ExitCode int `json:"exit_code"` | ||
Error string `json:"error"` | ||
Command string `json:"command"` | ||
} | ||
|
||
type CheckpointTelemetry struct { | ||
enabled bool | ||
spans []*TelemetrySpan | ||
signatureFile string | ||
startTime time.Time | ||
} | ||
|
||
func (c *CheckpointTelemetry) Enable(disableSignature bool) { | ||
configDir, err := ConfigDir() | ||
if err != nil { | ||
log.Printf("[ERR] Checkpoint telemetry setup error: %s", err) | ||
return | ||
} | ||
|
||
signatureFile := "" | ||
if disableSignature { | ||
log.Printf("[INFO] Checkpoint telemetry signature disabled") | ||
} else { | ||
signatureFile = filepath.Join(configDir, "checkpoint_signature") | ||
} | ||
|
||
c.signatureFile = signatureFile | ||
c.enabled = true | ||
} | ||
|
||
func (c *CheckpointTelemetry) baseParams(prefix string) *checkpoint.ReportParams { | ||
version := packerVersion.Version | ||
if packerVersion.VersionPrerelease != "" { | ||
version += fmt.Sprintf("-%s", packerVersion.VersionPrerelease) | ||
} | ||
|
||
return &checkpoint.ReportParams{ | ||
Product: "packer", | ||
SchemaVersion: prefix, | ||
StartTime: c.startTime, | ||
Version: version, | ||
RunID: os.Getenv("PACKER_RUN_UUID"), | ||
SignatureFile: c.signatureFile, | ||
} | ||
} | ||
|
||
func (c *CheckpointTelemetry) log(m string, args ...interface{}) { | ||
} | ||
|
||
func (c *CheckpointTelemetry) ReportPanic(m string) error { | ||
if !c.enabled { | ||
return nil | ||
} | ||
log.Printf("[TELEMETRY] Add panic: %s", m) | ||
panicParams := c.baseParams(TelemetryPanicVersion) | ||
panicParams.Payload = m | ||
panicParams.EndTime = time.Now().UTC() | ||
return checkpoint.Report(panicParams) | ||
} | ||
|
||
func (c *CheckpointTelemetry) AddSpan(name, pluginType string) *TelemetrySpan { | ||
log.Printf("[TELEMETRY] Starting %s %s", pluginType, name) | ||
ts := &TelemetrySpan{ | ||
Name: name, | ||
Type: pluginType, | ||
StartTime: time.Now().UTC(), | ||
} | ||
c.spans = append(c.spans, ts) | ||
return ts | ||
} | ||
|
||
func (c *CheckpointTelemetry) Finalize(command string, errCode int, err error) error { | ||
if !c.enabled { | ||
return nil | ||
} | ||
|
||
log.Printf("[TELEMETRY] finalize: %#v", c) | ||
params := c.baseParams(TelemetryVersion) | ||
params.EndTime = time.Now().UTC() | ||
|
||
extra := &PackerReport{ | ||
Spans: c.spans, | ||
ExitCode: errCode, | ||
Command: command, | ||
} | ||
if err != nil { | ||
extra.Error = err.Error() | ||
} | ||
params.Payload = extra | ||
|
||
return checkpoint.Report(params) | ||
} | ||
|
||
type TelemetrySpan struct { | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
StartTime time.Time `json:"start_time"` | ||
EndTime time.Time `json:"end_time"` | ||
Error string `json:"error"` | ||
} | ||
|
||
func (s *TelemetrySpan) End(err error) { | ||
s.EndTime = time.Now().UTC() | ||
log.Printf("[TELEMETRY] ending %s", s.Name) | ||
if err != nil { | ||
s.Error = err.Error() | ||
log.Printf("[TELEMETRY] ERROR: %s", err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
vendor/github.com/aws/aws-sdk-go/private/endpoints/endpoints.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.