Enable tracing when collecting metrics

pull/9808/head
Priya Wadhwa 2020-11-30 10:24:15 -08:00
parent f3ffb7e966
commit a2bc2fe64c
4 changed files with 20 additions and 10 deletions

View File

@ -1,4 +1,12 @@
This script runs `minikube start` in a loop and measures how long it takes.
It exports this data to Stackdriver via the OpenTelemetry API.
To run this script, run:
```
MINIKUBE_GCP_PROJECT_ID=<GCP Project ID> go run hack/metrics/*.go
```
This script is used to track minikube performance and prevent regressions.
_Note: this script will export data to both Cloud Monitoring and Cloud Trace in the provided GCP project_

View File

@ -31,10 +31,10 @@ import (
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"go.opencensus.io/trace"
pkgtrace "k8s.io/minikube/pkg/trace"
)
const (
projectEnvVar = "MINIKUBE_GCP_PROJECT_ID"
customMetricName = "custom.googleapis.com/minikube/start_time"
profile = "cloud-monitoring"
)
@ -52,9 +52,9 @@ func main() {
}
func execute() error {
projectID := os.Getenv(projectEnvVar)
projectID := os.Getenv(pkgtrace.ProjectEnvVar)
if projectID == "" {
return fmt.Errorf("metrics collector requires a valid GCP project id set via the %s env variable", projectEnvVar)
return fmt.Errorf("metrics collector requires a valid GCP project id set via the %s env variable", pkgtrace.ProjectEnvVar)
}
osMethod, err := tag.NewKey("os")
@ -98,7 +98,7 @@ func execute() error {
defer sd.StopMetricsExporter()
ctx := context.Background()
for {
st, err := minikubeStartTime(ctx)
st, err := minikubeStartTime(ctx, projectID)
if err != nil {
log.Printf("error collecting start time: %v", err)
continue
@ -109,7 +109,7 @@ func execute() error {
}
}
func minikubeStartTime(ctx context.Context) (float64, error) {
func minikubeStartTime(ctx context.Context, projectID string) (float64, error) {
minikubePath, err := downloadMinikube()
if err != nil {
return 0, errors.Wrap(err, "downloading minikube")
@ -117,7 +117,8 @@ func minikubeStartTime(ctx context.Context) (float64, error) {
defer os.Remove(minikubePath)
defer deleteMinikube(ctx, minikubePath)
cmd := exec.CommandContext(ctx, minikubePath, "start", "--driver=docker", "-p", profile, "--memory=2000")
cmd := exec.CommandContext(ctx, minikubePath, "start", "--driver=docker", "-p", profile, "--memory=2000", "--trace=gcp")
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", pkgtrace.ProjectEnvVar, projectID))
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr

View File

@ -30,7 +30,7 @@ import (
)
const (
bucketName = "priya-test-bucket/latest"
bucketName = "minikube/latest"
)
// download minikube latest to a tmp file

View File

@ -31,7 +31,8 @@ import (
)
const (
projectEnvVar = "MINIKUBE_GCP_PROJECT_ID"
// ProjectEnvVar is the name of the env variable that the user must pass in their GCP project ID through
ProjectEnvVar = "MINIKUBE_GCP_PROJECT_ID"
// this is the name of the parent span to help identify it
// in the Cloud Trace UI.
parentSpanName = "minikube start"
@ -72,9 +73,9 @@ func (t *gcpTracer) Cleanup() {
}
func initGCPTracer() (*gcpTracer, error) {
projectID := os.Getenv(projectEnvVar)
projectID := os.Getenv(ProjectEnvVar)
if projectID == "" {
return nil, fmt.Errorf("GCP tracer requires a valid GCP project id set via the %s env variable", projectEnvVar)
return nil, fmt.Errorf("GCP tracer requires a valid GCP project id set via the %s env variable", ProjectEnvVar)
}
_, flush, err := texporter.InstallNewPipeline(