Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cloud logs configuration to PLZ test runs by default #464

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions controllers/plz_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type PrivateLoadZoneReconciler struct {
// poller should be made PLZ specific;
// e.g. with a map: PLZ name -> poller.
poller *cloud.TestRunPoller
token string // needed for cloud logs
}

//+kubebuilder:rbac:groups=k6.io,resources=privateloadzones,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -88,6 +89,7 @@ func (r *PrivateLoadZoneReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}

r.poller = cloud.NewTestRunPoller(cloud.ApiURL(k6CloudHost()), token, plz.Name, logger)
r.token = token
}

if plz.DeletionTimestamp.IsZero() && (plz.IsUnknown(v1alpha1.PLZRegistered) || plz.IsFalse(v1alpha1.PLZRegistered)) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/plz_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (r *PrivateLoadZoneReconciler) startFactory(plz *v1alpha1.PrivateLoadZone,
continue
}

k6 = testrun.NewPLZTestRun(plz, trData, k6CloudHost())
k6 = testrun.NewPLZTestRun(plz, r.token, trData, k6CloudHost())

logger.Info(fmt.Sprintf("PLZ test run has been prepared with image `%s` and `%d` instances",
k6.Spec.Runner.Image, k6.Spec.Parallelism), "testRunId", testRunId)
Expand Down
9 changes: 6 additions & 3 deletions pkg/testrun/plz.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestName(testRunId string) string {
}

// ingestURL is a temp hack
func NewPLZTestRun(plz *v1alpha1.PrivateLoadZone, trData *cloud.TestRunData, ingestUrl string) *v1alpha1.TestRun {
func NewPLZTestRun(plz *v1alpha1.PrivateLoadZone, token string, trData *cloud.TestRunData, ingestUrl string) *v1alpha1.TestRun {
volume := corev1.Volume{
Name: "archive-volume",
VolumeSource: corev1.VolumeSource{
Expand Down Expand Up @@ -72,8 +72,11 @@ func NewPLZTestRun(plz *v1alpha1.PrivateLoadZone, trData *cloud.TestRunData, ing
},
Parallelism: int32(trData.InstanceCount),
Separate: false,
Arguments: "--out cloud --no-thresholds",
Cleanup: v1alpha1.Cleanup("post"),
Arguments: fmt.Sprintf(`--out cloud --no-thresholds --log-output=loki=https://cloudlogs.k6.io/api/v1/push,label.lz=%s,label.test_run_id=%s,header.Authorization="Token %s"`,
plz.Name,
trData.TestRunID(),
token),
Cleanup: v1alpha1.Cleanup("post"),

TestRunID: trData.TestRunID(),
Token: plz.Spec.Token,
Expand Down
9 changes: 7 additions & 2 deletions pkg/testrun/plz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testrun

import (
"fmt"
"strings"
"testing"

"github.com/go-test/deep"
Expand Down Expand Up @@ -53,7 +54,7 @@ func Test_NewPLZTestRun(t *testing.T) {
},
Parallelism: int32(0),
Separate: false,
Arguments: "--out cloud --no-thresholds",
Arguments: "--out cloud --no-thresholds --log-output=loki=https://cloudlogs.k6.io/api/v1/push,label.lz=,label.test_run_id=0,header.Authorization=\"Token token\"",
Cleanup: v1alpha1.Cleanup("post"),

TestRunID: "0",
Expand Down Expand Up @@ -101,6 +102,10 @@ func Test_NewPLZTestRun(t *testing.T) {
cloudFieldsTestRun = requiredFieldsTestRun // build up on top of required field case
cloudFieldsTestRun.ObjectMeta.Name = TestName(fmt.Sprintf("%d", someTestRunID))
cloudFieldsTestRun.Spec.TestRunID = fmt.Sprintf("%d", someTestRunID)
cloudFieldsTestRun.Spec.Arguments = strings.Replace(requiredFieldsTestRun.Spec.Arguments,
"test_run_id=0",
fmt.Sprintf("test_run_id=%d", someTestRunID),
1)
cloudFieldsTestRun.Spec.Runner.InitContainers = []v1alpha1.InitContainer{
containers.NewS3InitContainer(
someArchiveURL,
Expand Down Expand Up @@ -223,7 +228,7 @@ func Test_NewPLZTestRun(t *testing.T) {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
got := NewPLZTestRun(testCase.plz, testCase.cloudData, testCase.ingestUrl)
got := NewPLZTestRun(testCase.plz, "token", testCase.cloudData, testCase.ingestUrl)
if diff := deep.Equal(got, testCase.expected); diff != nil {
t.Errorf("NewPLZTestRun returned unexpected data, diff: %s", diff)
}
Expand Down
Loading