Enable tracing when collecting metrics
parent
f3ffb7e966
commit
a2bc2fe64c
|
@ -1,4 +1,12 @@
|
||||||
This script runs `minikube start` in a loop and measures how long it takes.
|
This script runs `minikube start` in a loop and measures how long it takes.
|
||||||
It exports this data to Stackdriver via the OpenTelemetry API.
|
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.
|
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_
|
||||||
|
|
|
@ -31,10 +31,10 @@ import (
|
||||||
"go.opencensus.io/stats/view"
|
"go.opencensus.io/stats/view"
|
||||||
"go.opencensus.io/tag"
|
"go.opencensus.io/tag"
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
|
pkgtrace "k8s.io/minikube/pkg/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
projectEnvVar = "MINIKUBE_GCP_PROJECT_ID"
|
|
||||||
customMetricName = "custom.googleapis.com/minikube/start_time"
|
customMetricName = "custom.googleapis.com/minikube/start_time"
|
||||||
profile = "cloud-monitoring"
|
profile = "cloud-monitoring"
|
||||||
)
|
)
|
||||||
|
@ -52,9 +52,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func execute() error {
|
func execute() error {
|
||||||
projectID := os.Getenv(projectEnvVar)
|
projectID := os.Getenv(pkgtrace.ProjectEnvVar)
|
||||||
if projectID == "" {
|
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")
|
osMethod, err := tag.NewKey("os")
|
||||||
|
@ -98,7 +98,7 @@ func execute() error {
|
||||||
defer sd.StopMetricsExporter()
|
defer sd.StopMetricsExporter()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
for {
|
for {
|
||||||
st, err := minikubeStartTime(ctx)
|
st, err := minikubeStartTime(ctx, projectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error collecting start time: %v", err)
|
log.Printf("error collecting start time: %v", err)
|
||||||
continue
|
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()
|
minikubePath, err := downloadMinikube()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrap(err, "downloading minikube")
|
return 0, errors.Wrap(err, "downloading minikube")
|
||||||
|
@ -117,7 +117,8 @@ func minikubeStartTime(ctx context.Context) (float64, error) {
|
||||||
defer os.Remove(minikubePath)
|
defer os.Remove(minikubePath)
|
||||||
defer deleteMinikube(ctx, 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.Stdout = os.Stderr
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
bucketName = "priya-test-bucket/latest"
|
bucketName = "minikube/latest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// download minikube latest to a tmp file
|
// download minikube latest to a tmp file
|
||||||
|
|
|
@ -31,7 +31,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
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
|
// this is the name of the parent span to help identify it
|
||||||
// in the Cloud Trace UI.
|
// in the Cloud Trace UI.
|
||||||
parentSpanName = "minikube start"
|
parentSpanName = "minikube start"
|
||||||
|
@ -72,9 +73,9 @@ func (t *gcpTracer) Cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func initGCPTracer() (*gcpTracer, error) {
|
func initGCPTracer() (*gcpTracer, error) {
|
||||||
projectID := os.Getenv(projectEnvVar)
|
projectID := os.Getenv(ProjectEnvVar)
|
||||||
if projectID == "" {
|
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(
|
_, flush, err := texporter.InstallNewPipeline(
|
||||||
|
|
Loading…
Reference in New Issue