Skip to content

Commit b9d6be1

Browse files
committed
feat: [CI-19120]: Send parentid and uniqueid to ci builds for ti
1 parent 789b03b commit b9d6be1

File tree

10 files changed

+28
-16
lines changed

10 files changed

+28
-16
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/go-chi/chi/v5 v5.0.8
1717
github.com/gofrs/uuid v4.4.0+incompatible
1818
github.com/golang/mock v1.6.0
19-
github.com/harness/ti-client v0.0.0-20250924143342-45bda4c46b0b
19+
github.com/harness/ti-client v0.0.0-20251017113419-0a8b7f6233b5
2020
github.com/hashicorp/go-multierror v1.1.1
2121
github.com/kelseyhightower/envconfig v1.4.0
2222
github.com/linkedin/goavro/v2 v2.12.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ github.com/harness/godotenv/v3 v3.0.1 h1:7QPEOkpx6SLLrYRRzPBp50d6c0XIxq721iqoFxb
8484
github.com/harness/godotenv/v3 v3.0.1/go.mod h1:UIXXJtTM7NkSYMYknHYOO2d8BfDlAWMYZRuRsXcDDR0=
8585
github.com/harness/godotenv/v4 v4.0.2 h1:w1ejcvR28wP67gKoMQ2aKRf+kI0Xorg/BetCwoG9KFs=
8686
github.com/harness/godotenv/v4 v4.0.2/go.mod h1:qpW/aRsktzrskWfKSHclHlvIp6+DJlmlYZXHQT+HBlE=
87-
github.com/harness/ti-client v0.0.0-20250924143342-45bda4c46b0b h1:HU5ytOP0XovoEbgqLUjF2x+r/PR1bH9qC+rqwHxnJ6c=
88-
github.com/harness/ti-client v0.0.0-20250924143342-45bda4c46b0b/go.mod h1:dGKnH3sg7UvBL2OztrqIusmsiBknSNy1Y5+9M2J241Q=
87+
github.com/harness/ti-client v0.0.0-20251017113419-0a8b7f6233b5 h1:Hiw9777zlEJpf+9IZHoNymJM8oTLru4jaCEzNT1ne2s=
88+
github.com/harness/ti-client v0.0.0-20251017113419-0a8b7f6233b5/go.mod h1:dGKnH3sg7UvBL2OztrqIusmsiBknSNy1Y5+9M2J241Q=
8989
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
9090
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
9191
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=

handler/setup.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func HandleSetup(engine *engine.Engine) http.HandlerFunc {
7878

7979
setProxyEnvs(s.Envs)
8080
state := pipeline.GetState()
81-
state.Set(s.Secrets, s.LogConfig, getTiCfg(&s.TIConfig, &s.MtlsConfig), s.MtlsConfig, collector)
81+
state.Set(s.Secrets, s.LogConfig, getTiCfg(&s.TIConfig, &s.MtlsConfig, s.Envs), s.MtlsConfig, collector)
8282

8383
if s.MountDockerSocket == nil || *s.MountDockerSocket { // required to support m1 where docker isn't installed.
8484
s.Volumes = append(s.Volumes, getDockerSockVolume())
@@ -157,8 +157,13 @@ func setProxyEnvs(environment map[string]string) {
157157
}
158158
}
159159

160-
func getTiCfg(t *api.TIConfig, mtlsConfig *spec.MtlsConfig) tiCfg.Cfg {
160+
func getTiCfg(t *api.TIConfig, mtlsConfig *spec.MtlsConfig, envs map[string]string) tiCfg.Cfg {
161+
// Extract parent unique ID from environment variables
162+
parentUniqueID := ""
163+
if envs != nil {
164+
parentUniqueID = envs["HARNESS_PARENT_UNIQUE_ID"]
165+
}
161166
cfg := tiCfg.New(t.URL, t.Token, t.AccountID, t.OrgID, t.ProjectID, t.PipelineID, t.BuildID, t.StageID, t.Repo,
162-
t.Sha, t.CommitLink, t.SourceBranch, t.TargetBranch, t.CommitBranch, pipeline.SharedVolPath, t.ParseSavings, false, mtlsConfig.ClientCert, mtlsConfig.ClientCertKey)
167+
t.Sha, t.CommitLink, t.SourceBranch, t.TargetBranch, t.CommitBranch, pipeline.SharedVolPath, parentUniqueID, t.ParseSavings, false, mtlsConfig.ClientCert, mtlsConfig.ClientCertKey)
163168
return cfg
164169
}

pipeline/runtime/runtest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func Test_CollectRunTestData(t *testing.T) {
2222
stepName := "RunTests"
2323
tiConfig := tiCfg.New("app.harness.io", "", "", "", "", "",
2424
"", "", "", "", "", "", "", "",
25-
"", false, false, "", "")
25+
"", "", false, false, "", "")
2626

2727
telemetryData := types.TelemetryData{}
2828

pipeline/runtime/runtestsV2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Test_CollectRunTestsV2Data(t *testing.T) {
2727
stepName := "RunTestsV2"
2828
tiConfig := tiCfg.New("app.harness.io", "", "", "", "", "",
2929
"", "", "", "", "", "", "", "",
30-
"", false, false, "", "")
30+
"", "", false, false, "", "")
3131

3232
tests := []struct {
3333
name string

pipeline/runtime/step_executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (e *StepExecutor) executeStep(r *api.StartStepRequest, wr logstream.Writer)
312312
tiConfig = state.GetTIConfig()
313313
}
314314
if (tiConfig == nil || tiConfig.GetURL() == "") && r.TIConfig.URL != "" {
315-
g := getTiCfg(&r.TIConfig, &r.MtlsConfig)
315+
g := getTiCfg(&r.TIConfig, &r.MtlsConfig, r.Envs)
316316
tiConfig = &g
317317
}
318318
ctx := context.Background()

pipeline/runtime/step_executor_stateless.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package runtime
66

77
import (
88
"context"
9+
"fmt"
910
"io"
1011

1112
"github.com/docker/docker/client"
@@ -68,14 +69,20 @@ func (e *StepExecutorStateless) executeStep( //nolint:gocritic
6869
return engine.RunStep(ctx, engine.Opts{Opts: docker.Opts{DockerClient: dockerClient}}, step, output, cfg, isDrone, isHosted)
6970
}
7071
// Temporary: this should be removed once we have a better way of handling test intelligence.
71-
tiConfig := getTiCfg(&r.TIConfig, &r.MtlsConfig)
72+
tiConfig := getTiCfg(&r.TIConfig, &r.MtlsConfig, r.Envs)
7273

7374
r.DeleteTempStepFiles = true
7475
return executeStepHelper(ctx, r, runFunc, writer, &tiConfig)
7576
}
7677

77-
func getTiCfg(t *api.TIConfig, mtlsConfig *spec.MtlsConfig) tiCfg.Cfg {
78+
func getTiCfg(t *api.TIConfig, mtlsConfig *spec.MtlsConfig, envs map[string]string) tiCfg.Cfg {
79+
// Extract parent unique ID from environment variables
80+
parentUniqueID := ""
81+
if envs != nil {
82+
parentUniqueID = envs["HARNESS_PARENT_UNIQUE_ID"]
83+
}
84+
fmt.Println("Parent Unique ID: ", parentUniqueID)
7885
cfg := tiCfg.New(t.URL, t.Token, t.AccountID, t.OrgID, t.ProjectID, t.PipelineID, t.BuildID, t.StageID, t.Repo,
79-
t.Sha, t.CommitLink, t.SourceBranch, t.TargetBranch, t.CommitBranch, pipeline.SharedVolPath, t.ParseSavings, false, mtlsConfig.ClientCert, mtlsConfig.ClientCertKey)
86+
t.Sha, t.CommitLink, t.SourceBranch, t.TargetBranch, t.CommitBranch, pipeline.SharedVolPath, parentUniqueID, t.ParseSavings, false, mtlsConfig.ClientCert, mtlsConfig.ClientCertKey)
8087
return cfg
8188
}

ti/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ type Cfg struct {
3232
}
3333

3434
func New(endpoint, token, accountID, orgID, projectID, pipelineID, buildID, stageID, repo, sha, commitLink,
35-
sourceBranch, targetBranch, commitBranch, dataDir string, parseSavings, skipVerify bool, mtlsClientCert, mtlsClientCertKey string) Cfg {
35+
sourceBranch, targetBranch, commitBranch, dataDir, parentUniqueID string, parseSavings, skipVerify bool, mtlsClientCert, mtlsClientCertKey string) Cfg {
3636
tiClient := client.NewHTTPClient(
37-
endpoint, token, accountID, orgID, projectID, pipelineID, buildID, stageID, repo, sha, commitLink, skipVerify, "", mtlsClientCert, mtlsClientCertKey)
37+
endpoint, token, accountID, orgID, projectID, pipelineID, buildID, stageID, repo, sha, commitLink, skipVerify, "", mtlsClientCert, mtlsClientCertKey, parentUniqueID)
3838
cfg := Cfg{
3939
mu: &sync.Mutex{},
4040
ziplocked: 1,

ti/instrumentation/instrumentation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func TestComputeSelected(t *testing.T) { //nolint:funlen
303303
selectTestsResponse.Tests = tt.runnableTests
304304
tiConfig := tiCfg.New("app.harness.io", "", "", "", "", "",
305305
"", "", "", "", "", "", "", "",
306-
"", false, false, "", "")
306+
"", "", false, false, "", "")
307307

308308
computeSelectedTests(ctx, config, log, runner, &selectTestsResponse, stepID, "", envs, &tiConfig)
309309

ti/instrumentation/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Test_GetSplitTests(t *testing.T) {
2121

2222
tiConfig := tiCfg.New("app.harness.io", "", "", "", "", "",
2323
"", "", "", "", "", "", "", "",
24-
"", false, false, "", "")
24+
"", "", false, false, "", "")
2525

2626
testsToSplit := []ti.RunnableTest{
2727
{Pkg: "pkg1", Class: "cls1"},

0 commit comments

Comments
 (0)