Skip to content

Commit 784c148

Browse files
authored
chore(telemetry): report stage template name (#5553)
1 parent 15eb019 commit 784c148

File tree

5 files changed

+80
-75
lines changed

5 files changed

+80
-75
lines changed

pkg/splunk/data.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ type Details struct {
1616

1717
// MonitoringData definition for monitoring
1818
type MonitoringData struct {
19-
PipelineUrlHash string `json:"PipelineUrlHash,omitempty"`
20-
BuildUrlHash string `json:"BuildUrlHash,omitempty"`
21-
Orchestrator string `json:"Orchestrator,omitempty"`
22-
// TemplateName indicates what template was used to run the pipeline (gpp, oss, ctp or custom)
23-
TemplateName string `json:"TemplateName,omitempty"`
24-
PiperCommitHash string `json:"PiperCommitHash,omitempty"`
25-
StageName string `json:"StageName,omitempty"`
26-
StepName string `json:"StepName,omitempty"`
27-
ExitCode string `json:"ExitCode,omitempty"`
28-
Duration string `json:"Duration,omitempty"`
29-
ErrorCode string `json:"ErrorCode,omitempty"`
30-
ErrorCategory string `json:"ErrorCategory,omitempty"`
31-
ErrorMessage string `json:"ErrorMessage,omitempty"`
32-
CorrelationID string `json:"CorrelationId,omitempty"`
33-
CommitHash string `json:"CommitHash,omitempty"`
34-
Branch string `json:"Branch,omitempty"`
35-
GitOwner string `json:"GitOwner,omitempty"`
36-
GitRepository string `json:"GitRepository,omitempty"`
19+
PipelineUrlHash string `json:"PipelineUrlHash,omitempty"`
20+
BuildUrlHash string `json:"BuildUrlHash,omitempty"`
21+
Orchestrator string `json:"Orchestrator,omitempty"`
22+
TemplateName string `json:"TemplateName,omitempty"`
23+
StageTemplateName string `json:"StageTemplateName,omitempty"`
24+
PiperCommitHash string `json:"PiperCommitHash,omitempty"`
25+
StageName string `json:"StageName,omitempty"`
26+
StepName string `json:"StepName,omitempty"`
27+
ExitCode string `json:"ExitCode,omitempty"`
28+
Duration string `json:"Duration,omitempty"`
29+
ErrorCode string `json:"ErrorCode,omitempty"`
30+
ErrorCategory string `json:"ErrorCategory,omitempty"`
31+
ErrorMessage string `json:"ErrorMessage,omitempty"`
32+
CorrelationID string `json:"CorrelationId,omitempty"`
33+
CommitHash string `json:"CommitHash,omitempty"`
34+
Branch string `json:"Branch,omitempty"`
35+
GitOwner string `json:"GitOwner,omitempty"`
36+
GitRepository string `json:"GitRepository,omitempty"`
3737
}
3838

3939
type LogFileEvent struct {

pkg/splunk/splunk.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,24 @@ func (s *Splunk) prepareTelemetry(telemetryData telemetry.Data) MonitoringData {
135135
}
136136

137137
monitoringData := MonitoringData{
138-
PipelineUrlHash: telemetryData.PipelineURLHash,
139-
BuildUrlHash: telemetryData.BuildURLHash,
140-
Orchestrator: telemetryData.Orchestrator,
141-
TemplateName: telemetryData.TemplateName,
142-
PiperCommitHash: telemetryData.PiperCommitHash,
143-
StageName: telemetryData.StageName,
144-
StepName: telemetryData.BaseData.StepName,
145-
ExitCode: telemetryData.CustomData.ErrorCode,
146-
Duration: telemetryData.CustomData.Duration,
147-
ErrorCode: telemetryData.CustomData.ErrorCode,
148-
ErrorCategory: telemetryData.CustomData.ErrorCategory,
149-
ErrorMessage: errorMessage,
150-
CorrelationID: s.correlationID,
151-
CommitHash: readCommonPipelineEnvironment("git/headCommitId"),
152-
Branch: readCommonPipelineEnvironment("git/branch"),
153-
GitOwner: readCommonPipelineEnvironment("git/organization"),
154-
GitRepository: readCommonPipelineEnvironment("git/repository"),
138+
PipelineUrlHash: telemetryData.PipelineURLHash,
139+
BuildUrlHash: telemetryData.BuildURLHash,
140+
Orchestrator: telemetryData.Orchestrator,
141+
TemplateName: telemetryData.TemplateName,
142+
StageTemplateName: telemetryData.StageTemplateName,
143+
PiperCommitHash: telemetryData.PiperCommitHash,
144+
StageName: telemetryData.StageName,
145+
StepName: telemetryData.BaseData.StepName,
146+
ExitCode: telemetryData.CustomData.ErrorCode,
147+
Duration: telemetryData.CustomData.Duration,
148+
ErrorCode: telemetryData.CustomData.ErrorCode,
149+
ErrorCategory: telemetryData.CustomData.ErrorCategory,
150+
ErrorMessage: errorMessage,
151+
CorrelationID: s.correlationID,
152+
CommitHash: readCommonPipelineEnvironment("git/headCommitId"),
153+
Branch: readCommonPipelineEnvironment("git/branch"),
154+
GitOwner: readCommonPipelineEnvironment("git/organization"),
155+
GitRepository: readCommonPipelineEnvironment("git/repository"),
155156
}
156157
monitoringJson, err := json.Marshal(monitoringData)
157158
if err != nil {

pkg/splunk/splunk_test.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,9 @@ func Test_prepareTelemetry(t *testing.T) {
357357
args: args{
358358
telemetryData: telemetry.Data{
359359
BaseData: telemetry.BaseData{
360-
Orchestrator: "Jenkins",
361-
TemplateName: "hyperspace-piper-gpp",
360+
Orchestrator: "Jenkins",
361+
TemplateName: "hyperspace-piper-gpp",
362+
StageTemplateName: "hyperspace-piper-gpp-build",
362363
},
363364
CustomData: telemetry.CustomData{
364365
Duration: "1234",
@@ -368,22 +369,23 @@ func Test_prepareTelemetry(t *testing.T) {
368369
},
369370
},
370371
want: MonitoringData{
371-
PipelineUrlHash: "",
372-
BuildUrlHash: "",
373-
Orchestrator: "Jenkins",
374-
TemplateName: "hyperspace-piper-gpp",
375-
StageName: "",
376-
StepName: "",
377-
ExitCode: "0",
378-
Duration: "1234",
379-
ErrorCode: "0",
380-
ErrorCategory: "Undefined",
381-
ErrorMessage: "",
382-
CorrelationID: "Correlation-Test",
383-
CommitHash: "N/A",
384-
Branch: "N/A",
385-
GitOwner: "N/A",
386-
GitRepository: "N/A",
372+
PipelineUrlHash: "",
373+
BuildUrlHash: "",
374+
Orchestrator: "Jenkins",
375+
TemplateName: "hyperspace-piper-gpp",
376+
StageTemplateName: "hyperspace-piper-gpp-build",
377+
StageName: "",
378+
StepName: "",
379+
ExitCode: "0",
380+
Duration: "1234",
381+
ErrorCode: "0",
382+
ErrorCategory: "Undefined",
383+
ErrorMessage: "",
384+
CorrelationID: "Correlation-Test",
385+
CommitHash: "N/A",
386+
Branch: "N/A",
387+
GitOwner: "N/A",
388+
GitRepository: "N/A",
387389
},
388390
},
389391
}

pkg/telemetry/data.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import (
77

88
// BaseData object definition containing the base data
99
type BaseData struct {
10-
ActionName string `json:"actionName"`
11-
EventType string `json:"eventType"`
12-
SiteID string `json:"idsite"`
13-
URL string `json:"url"`
14-
StepName string `json:"stepName"` // set by step generator
15-
StageName string `json:"stageName"`
16-
PipelineURLHash string `json:"pipelineUrlHash"` // defaults to sha1 of provider.GetBuildURL()
17-
BuildURLHash string `json:"buildUrlHash"` // defaults to sha1 of provider.GetJobURL()
18-
Orchestrator string `json:"orchestrator"` // defaults to provider.OrchestratorType()
19-
// TemplateName indicates what template was used to run the pipeline (gpp, oss, ctp or custom)
20-
TemplateName string `json:"templateName"` // defaults to os.Getenv("PIPER_PIPELINE_TEMPLATE_NAME") or "n/a" if not set.
10+
ActionName string `json:"actionName"`
11+
EventType string `json:"eventType"`
12+
SiteID string `json:"idsite"`
13+
URL string `json:"url"`
14+
StepName string `json:"stepName"` // set by step generator
15+
StageName string `json:"stageName"`
16+
PipelineURLHash string `json:"pipelineUrlHash"` // defaults to sha1 of provider.GetBuildURL()
17+
BuildURLHash string `json:"buildUrlHash"` // defaults to sha1 of provider.GetJobURL()
18+
Orchestrator string `json:"orchestrator"` // defaults to provider.OrchestratorType()
19+
TemplateName string `json:"templateName"` // defaults to os.Getenv("PIPER_PIPELINE_TEMPLATE_NAME") or "n/a" if not set.
20+
StageTemplateName string `json:"stageTemplateName"` // defaults to os.Getenv("PIPER_PIPELINE_TEMPLATE_STAGE_NAME") or "n/a" if not set.
2121
}
2222

2323
var baseData BaseData

pkg/telemetry/telemetry.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"crypto/sha1"
55
"encoding/json"
66
"fmt"
7-
"github.com/SAP/jenkins-library/pkg/piperutils"
87
"os"
98
"strconv"
109
"time"
1110

11+
"github.com/SAP/jenkins-library/pkg/piperutils"
12+
1213
piperhttp "github.com/SAP/jenkins-library/pkg/http"
1314
"github.com/SAP/jenkins-library/pkg/log"
1415
"github.com/SAP/jenkins-library/pkg/orchestrator"
@@ -60,16 +61,17 @@ func (t *Telemetry) Initialize(stepName string) {
6061
}
6162

6263
t.baseData = BaseData{
63-
Orchestrator: t.provider.OrchestratorType(),
64-
TemplateName: piperutils.StringWithDefault(os.Getenv("PIPER_PIPELINE_TEMPLATE_NAME"), "n/a"),
65-
StageName: t.provider.StageName(),
66-
URL: LibraryRepository,
67-
ActionName: actionName,
68-
EventType: eventType,
69-
StepName: stepName,
70-
SiteID: t.SiteID,
71-
PipelineURLHash: t.getPipelineURLHash(), // URL (hashed value) which points to the project’s pipelines
72-
BuildURLHash: t.getBuildURLHash(), // URL (hashed value) which points to the pipeline that is currently running
64+
Orchestrator: t.provider.OrchestratorType(),
65+
TemplateName: piperutils.StringWithDefault(os.Getenv("PIPER_PIPELINE_TEMPLATE_NAME"), "n/a"),
66+
StageTemplateName: piperutils.StringWithDefault(os.Getenv("PIPER_PIPELINE_STAGE_TEMPLATE_NAME"), "n/a"),
67+
StageName: t.provider.StageName(),
68+
URL: LibraryRepository,
69+
ActionName: actionName,
70+
EventType: eventType,
71+
StepName: stepName,
72+
SiteID: t.SiteID,
73+
PipelineURLHash: t.getPipelineURLHash(), // URL (hashed value) which points to the project’s pipelines
74+
BuildURLHash: t.getBuildURLHash(), // URL (hashed value) which points to the pipeline that is currently running
7375
}
7476
}
7577

0 commit comments

Comments
 (0)