forked from pixie-io/pixie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
1611 lines (1435 loc) · 51.2 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Jenkins build definition. This file defines the entire build pipeline.
*/
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import jenkins.model.Jenkins
SRC_STASH_NAME = 'src'
TARGETS_STASH_NAME = 'targets'
DEV_DOCKER_IMAGE = 'gcr.io/pixie-oss/pixie-dev-public/dev_image'
DEV_DOCKER_IMAGE_EXTRAS = 'gcr.io/pixie-oss/pixie-dev-public/dev_image_with_extras'
GCLOUD_DOCKER_IMAGE = 'google/cloud-sdk:412.0.0-alpine'
GIT_DOCKER_IMAGE = 'bitnami/git:2.33.0'
K8S_PROD_CLUSTER = 'https://cloud-prod.internal.corp.pixielabs.ai'
// Our staging instance used to be run on our prod cluster. These creds are
// actually the creds for our prod cluster.
K8S_PROD_CREDS = 'cloud-staging'
K8S_STAGING_CLUSTER = 'https://cloud-staging.internal.corp.pixielabs.ai'
K8S_STAGING_CREDS = 'pixie-prod-staging-cluster'
K8S_TESTING_CLUSTER = 'https://cloud-testing.internal.corp.pixielabs.ai'
K8S_TESTING_CREDS = 'pixie-prod-testing-cluster'
// PXL Docs variables.
PXL_DOCS_BINARY = '//src/carnot/docstring:docstring'
PXL_DOCS_FILE = 'pxl-docs.json'
PXL_DOCS_BUCKET = 'pl-docs'
PXL_DOCS_GCS_PATH = "gs://${PXL_DOCS_BUCKET}/${PXL_DOCS_FILE}"
// BPF Setup.
// The default kernel should be the oldest supported kernel
// to ensure that we don't have BPF compatibility regressions.
BPF_DEFAULT_KERNEL = '4.14'
BPF_NEWEST_KERNEL = '5.19'
BPF_KERNELS = ['4.14', '4.19', '5.4', '5.10', '5.15', '5.19']
BPF_KERNELS_TO_TEST = [BPF_DEFAULT_KERNEL, BPF_NEWEST_KERNEL]
// Currently disabling TSAN on BPF builds because it runs too slow.
// In particular, the uprobe deployment takes far too long. See issue:
// https://pixie-labs.atlassian.net/browse/PL-1329
// The benefit of TSAN on such runs is marginal anyways, because the tests
// are mostly single-threaded.
runBPFWithTSAN = false
// TODO(yzhao/oazizi): PP-2276 Fix the BPF ASAN tests.
runBPFWithASAN = false
// This variable store the dev docker image that we need to parse before running any docker steps.
devDockerImageWithTag = ''
devDockerImageExtrasWithTag = ''
stashList = []
// Flag controlling if coverage job is enabled.
isMainCodeReviewRun = (env.JOB_NAME == 'pixie-oss/build-and-test-pr')
isReleaseRun = env.JOB_NAME.startsWith('pixie-release/')
isMainRun = (env.JOB_NAME == 'pixie-main/build-and-test-all')
isNightlyTestRegressionRun = (env.JOB_NAME == 'pixie-main/nightly-test-regression')
isNightlyBPFTestRegressionRun = (env.JOB_NAME == 'pixie-main/nightly-test-regression-bpf')
isOSSMainRun = (env.JOB_NAME == 'pixie-oss/build-and-test-all')
isOSSCloudBuildRun = env.JOB_NAME.startsWith('pixie-release/cloud/')
isOSSCodeReviewRun = env.JOB_NAME == 'pixie-oss/build-and-test-pr'
isOSSRun = isOSSMainRun || isOSSCloudBuildRun || isOSSCodeReviewRun || isReleaseRun
isCLIBuildRun = env.JOB_NAME.startsWith('pixie-release/cli/')
isOperatorBuildRun = env.JOB_NAME.startsWith('pixie-release/operator/')
isVizierBuildRun = env.JOB_NAME.startsWith('pixie-release/vizier/')
isCloudProdBuildRun = env.JOB_NAME.startsWith('pixie-release/cloud-prod/')
isCloudStagingBuildRun = env.JOB_NAME.startsWith('pixie-release/cloud-staging/')
isStirlingPerfEval = (env.JOB_NAME == 'pixie-main/stirling-perf-eval')
GCS_STASH_BUCKET = isOSSRun ? 'px-jenkins-build-oss' : 'px-jenkins-build-temp'
GCP_PROJECT = isOSSRun ? 'pixie-oss' : 'pl-dev-infra'
BES_GCE_FILE = isOSSRun ? 'ci/bes-oss-gce.bazelrc' : 'ci/bes-gce.bazelrc'
BES_K8S_FILE = isOSSRun ? 'ci/bes-oss-k8s.bazelrc' : 'ci/bes-k8s.bazelrc'
// Build tags are used to modify the behavior of the build.
// Note: Tags only work for code-review builds.
// Enable the BPF build, even if it's not required.
buildTagBPFBuild = false
// Enable BPF build across all tested kernels.
buildTagBPFBuildAllKernels = false
def gsutilCopy(String src, String dest) {
container('gcloud') {
sh "gsutil -o GSUtil:parallel_composite_upload_threshold=150M cp ${src} ${dest}"
}
}
def bbLinks() {
return "--build_metadata=BUILDBUDDY_LINKS='[Jenkins](${BUILD_URL})'"
}
def stashOnGCS(String name, String pattern) {
def destFile = "${name}.tar.gz"
sh "mkdir -p .archive && tar --exclude=.archive -czf .archive/${destFile} ${pattern}"
gsutilCopy(".archive/${destFile}", "gs://${GCS_STASH_BUCKET}/${env.BUILD_TAG}/${destFile}")
}
def fetchFromGCS(String name) {
def srcFile = "${name}.tar.gz"
sh 'mkdir -p .archive'
gsutilCopy("gs://${GCS_STASH_BUCKET}/${env.BUILD_TAG}/${srcFile}", ".archive/${srcFile}")
}
def unstashFromGCS(String name) {
def srcFile = "${name}.tar.gz"
fetchFromGCS(name)
// Note: The tar extraction must use `--no-same-owner`.
// Without this, the owner of some third_party files become invalid users,
// which causes some cmake projects to fail with "failed to preserve ownership" messages.
sh """
tar -zxf .archive/${srcFile} --no-same-owner
rm -f .archive/${srcFile}
"""
}
def shFileExists(String f) {
return sh(
script: "test -f ${f}",
returnStatus: true) == 0
}
def shFileEmpty(String f) {
return sh(
script: "test -s ${f}",
returnStatus: true) != 0
}
def createBazelStash(String stashName) {
sh '''
rm -rf bazel-testlogs-archive
mkdir -p bazel-testlogs-archive
cp -a bazel-testlogs/ bazel-testlogs-archive || true
'''
stashOnGCS(stashName, 'bazel-testlogs-archive/**')
stashList.add(stashName)
}
def retryOnK8sDownscale(Closure body, int times=5) {
for (int retryCount = 0; retryCount < times; retryCount++) {
try {
body()
return
} catch (io.fabric8.kubernetes.client.KubernetesClientException e) {
println("Caught ${e}, assuming K8s cluster downscaled, will retry.")
// Sleep an extra 5 seconds for each retry attempt.
def interval = (retryCount + 1) * 5
sleep interval
continue
} catch (e) {
println("Unhandled ${e}, assuming fatal error.")
throw e
}
}
}
def fetchSourceK8s(Closure body) {
container('gcloud') {
unstashFromGCS(SRC_STASH_NAME)
sh 'git config --global --add safe.directory `pwd`'
if (isOSSCodeReviewRun || isOSSMainRun) {
sh 'cp ci/bes-oss-k8s.bazelrc bes.bazelrc'
} else {
sh 'cp ci/bes-k8s.bazelrc bes.bazelrc'
}
}
body()
}
def fetchSourceAndTargetsK8s(Closure body) {
fetchSourceK8s {
container('gcloud') {
unstashFromGCS(TARGETS_STASH_NAME)
}
body()
}
}
def runBazelCmd(String f, String targetConfig, int retries = 5) {
def retval = sh(
script: "bazel ${f} ${bbLinks()} --build_metadata=CONFIG=${targetConfig}",
returnStatus: true
)
if (retval == 38 && (targetConfig == 'tsan' || targetConfig == 'asan')) {
// If bes update failed for a sanitizer run, re-run to get the real retval.
if (retries == 0) {
println('Bazel bes update failed for sanitizer run after multiple retries.')
return retval
}
println('Bazel bes update failed for sanitizer run, retrying...')
return runBazelCmd(f, targetConfig, retries - 1)
}
// 4 means that tests not present.
// 38 means that bes update failed.
// Both are not fatal.
if (retval == 0 || retval == 4 || retval == 38) {
if (retval != 0) {
println("Bazel returned ${retval}, ignoring...")
}
return 0
}
return retval
}
/**
* Runs bazel CI.
*
* The targetFilter can either be a bazel filter clause, or bazel path (//..., etc.), but not a list of paths.
*/
def bazelCICmd(String name, String targetConfig='clang', String targetCompilationMode='opt',
String targetsSuffix, String bazelRunExtraArgs='') {
def buildableFile = "bazel_buildables_${targetsSuffix}"
def testFile = "bazel_tests_${targetsSuffix}"
def args = "-c ${targetCompilationMode} --config=${targetConfig} --build_metadata=COMMIT_SHA=\$(git rev-parse HEAD) ${bazelRunExtraArgs}"
def buildRet = runBazelCmd("build ${args} --target_pattern_file ${buildableFile}", targetConfig)
if (buildRet != 0) {
unstable('Bazel build failed')
}
def testRet = runBazelCmd("test ${args} --target_pattern_file ${testFile}", targetConfig)
if (testRet == 0 || testRet == 3) {
// Create stash even when we get 3 as a retval which indicates some tests failed.
// This allows the test reporter to report on failing test names/counts.
createBazelStash("${name}-testlogs")
}
if (testRet != 0) {
unstable('Bazel test failed')
}
}
def processBazelLogs(String logBase) {
step([
$class: 'XUnitPublisher',
thresholds: [
[
$class: 'FailedThreshold',
unstableThreshold: '1'
]
],
tools: [
[
$class: 'GoogleTestType',
skipNoTestFiles: true,
pattern: "${logBase}/bazel-testlogs-archive/**/*.xml"
]
]
])
}
def processAllExtractedBazelLogs() {
stashList.each { stashName ->
if (stashName.endsWith('testlogs')) {
processBazelLogs(stashName)
}
}
}
def sendSlackNotification() {
if (currentBuild.result != 'SUCCESS' && currentBuild.result != null) {
slackSend color: '#FF0000', message: "FAILED: Build - ${env.BUILD_TAG} -- URL: ${env.BUILD_URL}."
}
else if (currentBuild.getPreviousBuild() &&
currentBuild.getPreviousBuild().getResult().toString() != 'SUCCESS') {
slackSend color: '#00FF00', message: "PASSED(Recovered): Build - ${env.BUILD_TAG} -- URL: ${env.BUILD_URL}."
}
}
def sendCloudReleaseSlackNotification(String profile) {
if (currentBuild.result == 'SUCCESS' || currentBuild.result == null) {
slackSend color: '#00FF00', message: "${profile} Cloud deployed - ${env.BUILD_TAG} -- URL: ${env.BUILD_URL}."
} else {
slackSend color: '#FF0000', message: "${profile} Cloud deployed FAILED - ${env.BUILD_TAG} -- URL: ${env.BUILD_URL}."
}
}
def postBuildActions = {
if (!isOSSRun) {
sendSlackNotification()
}
if (isOSSMainRun) {
step([$class: "GitHubCommitStatusSetter",]);
}
}
def initializeRepoState() {
sh 'git config --global --add safe.directory $(pwd)'
sh './ci/save_version_info.sh'
sh './ci/save_diff_info.sh'
withCredentials([
string(
credentialsId: 'buildbuddy-api-key',
variable: 'BUILDBUDDY_API_KEY'
),
string(
credentialsId: 'github-license-ratelimit',
variable: 'GH_API_KEY'
)
]) {
sh './ci/write_bazelrc.sh'
}
// Get docker image tag.
def properties = readProperties file: 'docker.properties'
devDockerImageWithTag = "${DEV_DOCKER_IMAGE}:${properties.DOCKER_IMAGE_TAG}@sha256:${properties.DEV_IMAGE_DIGEST}"
devDockerImageExtrasWithTag = "${DEV_DOCKER_IMAGE_EXTRAS}:${properties.DOCKER_IMAGE_TAG}@sha256:${properties.DEV_IMAGE_WITH_EXTRAS_DIGEST}"
stashOnGCS(SRC_STASH_NAME, '.')
}
// K8s related helpers
def gcloudContainer() {
containerTemplate(name: 'gcloud', image: GCLOUD_DOCKER_IMAGE, command: 'cat', ttyEnabled: true)
}
def gitContainer() {
containerTemplate(name: 'git', image: GIT_DOCKER_IMAGE, command: 'cat', ttyEnabled: true)
}
def pxdevContainer(boolean needExtras=false) {
def image = needExtras ? devDockerImageExtrasWithTag : devDockerImageWithTag
containerTemplate(name: 'pxdev', image: image, command: 'cat', ttyEnabled: true)
}
def pxbuildContainer(boolean needExtras=false) {
def image = needExtras ? devDockerImageExtrasWithTag : devDockerImageWithTag
containerTemplate(
name: 'pxbuild', image: image, command: 'cat', ttyEnabled: true,
resourceRequestMemory: '58368Mi', resourceRequestCpu: '30000m',
)
}
pxbuildPodPatch = '''
spec:
dnsPolicy: ClusterFirstWithHostNet
containers:
- name: pxbuild
securityContext:
capabilities:
add:
- SYS_PTRACE
'''
def retryPodTemplate(String suffix, List<org.csanchez.jenkins.plugins.kubernetes.ContainerTemplate> containers, Closure body) {
warnError('Script failed') {
retryOnK8sDownscale {
def label = "worker-${env.BUILD_TAG}-${suffix}"
podTemplate(label: label, cloud: 'devinfra-cluster-usw1-0', containers: containers) {
node(label) {
body()
}
}
}
}
}
def pxbuildRetryPodTemplate(String suffix, boolean needExtras=false, Closure body) {
warnError('Script failed') {
retryOnK8sDownscale {
def label = "worker-${env.BUILD_TAG}-${suffix}"
podTemplate(
label: label, cloud: 'devinfra-cluster-usw1-0', containers: [
pxbuildContainer(needExtras), gcloudContainer(),
],
yaml: pxbuildPodPatch,
yamlMergeStrategy: merge(),
hostNetwork: true,
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
hostPathVolume(mountPath: '/var/lib/docker', hostPath: '/var/lib/docker'),
hostPathVolume(mountPath: '/mnt/disks/jenkins/sharedDir', hostPath: '/mnt/disks/jenkins/sharedDir')
]) {
node(label) {
container('pxbuild') {
sh 'git config --global --add safe.directory `pwd`'
}
body()
}
}
}
}
}
def pxbuildWithSourceK8s(String suffix, boolean needExtras=false, Closure body) {
pxbuildRetryPodTemplate(suffix, needExtras) {
fetchSourceK8s {
timeout(time: 90, unit: 'MINUTES') {
body()
}
}
}
}
def pxbuildWithSourceAndTargetsK8s(String suffix, boolean needExtras=false, Closure body) {
pxbuildRetryPodTemplate(suffix, needExtras) {
fetchSourceAndTargetsK8s {
timeout(time: 90, unit: 'MINUTES') {
body()
}
}
}
}
/**
* Checkout the source code, record git info and stash sources.
*/
def checkoutAndInitialize() {
retryPodTemplate('init', [gcloudContainer()]) {
container('gcloud') {
deleteDir()
checkout scm
initializeRepoState()
if (isOSSCodeReviewRun) {
def logMessage = sh(
script: 'git log origin/main..',
returnStdout: true,
).trim()
def hasTag = { log, tag -> (log ==~ "(?s).*#ci:${tag }(\\s|\$).*") }
buildTagBPFBuild = hasTag(logMessage, 'bpf-build')
buildTagBPFBuildAllKernels = hasTag(logMessage, 'bpf-build-all-kernels')
}
}
}
}
def enableForTargets(String targetName, Closure body) {
if (!shFileEmpty("bazel_buildables_${targetName}") || !shFileEmpty("bazel_tests_${targetName}")) {
body()
}
}
/*****************************************************************************
* BUILDERS: This sections defines all the build steps that will happen in parallel.
*****************************************************************************/
def preBuild = [:]
def builders = [:]
def buildAndTestOptWithUI = {
pxbuildWithSourceAndTargetsK8s('build-opt') {
container('pxbuild') {
bazelCICmd('build-opt', 'clang', 'opt', 'clang_opt', '--action_env=GOOGLE_APPLICATION_CREDENTIALS')
}
}
}
def buildClangTidy = {
pxbuildWithSourceK8s('clang-tidy') {
container('pxbuild') {
def stashName = 'build-clang-tidy-logs'
if (isMainRun) {
// For main builds we run clang tidy on changes files in the past 10 revisions,
// this gives us a good balance of speed and coverage.
sh 'ci/run_clang_tidy.sh -f diff_head_cc'
} else {
// For code review builds only run on diff.
sh 'ci/run_clang_tidy.sh -f diff_origin_main_cc'
}
stashOnGCS(stashName, 'clang_tidy.log')
stashList.add(stashName)
}
}
}
def buildDbg = {
pxbuildWithSourceAndTargetsK8s('build-dbg') {
container('pxbuild') {
bazelCICmd('build-dbg', 'clang', 'dbg', 'clang_dbg', '--action_env=GOOGLE_APPLICATION_CREDENTIALS')
}
}
}
def buildGoRace = {
pxbuildWithSourceAndTargetsK8s('build-go-race') {
container('pxbuild') {
bazelCICmd('build-go-race', 'go_race', 'opt', 'go_race')
}
}
}
def buildASAN = {
pxbuildWithSourceAndTargetsK8s('build-asan') {
container('pxbuild') {
bazelCICmd('build-asan', 'asan', 'dbg', 'sanitizer')
}
}
}
def buildTSAN = {
pxbuildWithSourceAndTargetsK8s('build-tsan') {
container('pxbuild') {
bazelCICmd('build-tsan', 'tsan', 'dbg', 'sanitizer')
}
}
}
def buildGCC = {
pxbuildWithSourceAndTargetsK8s('build-gcc-opt') {
container('pxbuild') {
bazelCICmd('build-gcc-opt', 'gcc', 'opt', 'gcc_opt')
}
}
}
def bazelCICmdBPFonGCE(String name, String targetConfig='clang', String targetCompilationMode='opt',
String targetsSuffix, String bazelRunExtraArgs='', String kernel=BPF_DEFAULT_KERNEL) {
def buildableFile = "bazel_buildables_${targetsSuffix}"
def testFile = "bazel_tests_${targetsSuffix}"
def bazelArgs = "-c ${targetCompilationMode} --config=${targetConfig} --build_metadata=COMMIT_SHA=\$(git rev-parse HEAD) ${bazelRunExtraArgs}"
def stashName = "${name}-${kernel}-testlogs"
fetchFromGCS(SRC_STASH_NAME)
fetchFromGCS(TARGETS_STASH_NAME)
def retval = sh(
script: """
export BUILDABLE_FILE="${buildableFile}"
export TEST_FILE="${testFile}"
export BAZEL_ARGS="${bazelArgs}"
export STASH_NAME="${stashName}"
export GCS_STASH_BUCKET="${GCS_STASH_BUCKET}"
export BUILD_TAG="${BUILD_TAG}"
export KERNEL_VERSION="${kernel}"
export GCP_PROJECT="${GCP_PROJECT}"
export BES_FILE="${BES_GCE_FILE}"
./ci/bpf/00_create_instance.sh
""",
returnStatus: true
)
if (retval == 0 || retval == 3) {
stashList.add(stashName)
}
if (retval != 0) {
unstable('Bazel BPF build/test failed')
}
}
def buildAndTestBPFOpt = { kernel ->
retryPodTemplate('build-bpf-opt', [gcloudContainer()]) {
fetchSourceAndTargetsK8s {
container('gcloud') {
bazelCICmdBPFonGCE('build-bpf', 'bpf', 'opt', 'bpf', '', kernel)
}
}
}
}
def buildAndTestBPFASAN = { kernel ->
retryPodTemplate('build-bpf-asan', [gcloudContainer()]) {
fetchSourceAndTargetsK8s {
container('gcloud') {
bazelCICmdBPFonGCE('build-bpf-asan', 'bpf_asan', 'dbg', 'bpf_sanitizer', '', kernel)
}
}
}
}
def buildAndTestBPFTSAN = { kernel ->
retryPodTemplate('build-bpf-tsan', [gcloudContainer()]) {
fetchSourceAndTargetsK8s {
container('gcloud') {
bazelCICmdBPFonGCE('build-bpf-tsan', 'bpf_tsan', 'dbg', 'bpf_sanitizer', '', kernel)
}
}
}
}
def generateTestTargets = {
enableForTargets('clang_opt') {
builders['Build & Test (clang:opt + UI)'] = buildAndTestOptWithUI
}
enableForTargets('clang_tidy') {
builders['Clang-Tidy'] = buildClangTidy
}
enableForTargets('clang_dbg') {
builders['Build & Test (dbg)'] = buildDbg
}
enableForTargets('sanitizer') {
builders['Build & Test (asan)'] = buildASAN
}
enableForTargets('sanitizer') {
builders['Build & Test (tsan)'] = buildTSAN
}
enableForTargets('gcc_opt') {
builders['Build & Test (gcc:opt)'] = buildGCC
}
enableForTargets('go_race') {
builders['Build & Test (go race detector)'] = buildGoRace
}
BPF_KERNELS_TO_TEST.each { kernel ->
enableForTargets('bpf') {
builders["Build & Test (bpf tests - opt) - ${kernel}"] = { buildAndTestBPFOpt(kernel) }
}
if (runBPFWithASAN) {
enableForTargets('bpf_sanitizer') {
builders["Build & Test (bpf tests - asan) - ${kernel}"] = { buildAndTestBPFASAN(kernel) }
}
}
if (runBPFWithTSAN) {
enableForTargets('bpf_sanitizer') {
builders["Build & Test (bpf tests - tsan) - ${kernel}"] = { buildAndTestBPFTSAN(kernel) }
}
}
}
}
preBuild['Process Dependencies'] = {
retryPodTemplate('process-deps', [gcloudContainer(), pxdevContainer()]) {
fetchSourceK8s {
container('pxdev') {
sh 'git config --global --add safe.directory `pwd`'
def forceAll = ''
def enableBPF = ''
if (isMainRun || isNightlyTestRegressionRun || isOSSMainRun || isNightlyBPFTestRegressionRun) {
forceAll = '-a'
enableBPF = '-b'
}
if (buildTagBPFBuild || buildTagBPFBuildAllKernels) {
enableBPF = '-b'
}
sh """
./ci/bazel_build_deps.sh ${forceAll} ${enableBPF}
wc -l bazel_*
"""
if (buildTagBPFBuildAllKernels) {
BPF_KERNELS_TO_TEST = BPF_KERNELS
}
stashOnGCS(TARGETS_STASH_NAME, 'bazel_*')
generateTestTargets()
}
}
}
}
if (isMainRun || isOSSMainRun) {
def codecovToken = 'pixie-codecov-token'
def slug = 'pixie-labs/pixielabs'
if (isOSSMainRun) {
codecovToken = 'pixie-oss-codecov-token'
slug = 'pixie-io/pixie'
}
// Only run coverage on main runs.
builders['Build & Test (gcc:coverage)'] = {
pxbuildWithSourceAndTargetsK8s('coverage') {
container('pxbuild') {
warnError('Coverage command failed') {
withCredentials([
string(
credentialsId: codecovToken,
variable: 'CODECOV_TOKEN'
)
]) {
sh "ci/collect_coverage.sh -u -b main -c `cat GIT_COMMIT` -r " + slug
}
}
createBazelStash('build-gcc-coverage-testlogs')
}
}
}
}
def buildScriptForOSSCloudRelease = {
try {
stage('Checkout code') {
checkoutAndInitialize()
}
stage('Build & Push Artifacts') {
pxbuildWithSourceK8s('build-and-push-oss-cloud', true) {
container('pxbuild') {
sh './ci/cloud_build_release.sh -p'
}
}
}
}
catch (err) {
currentBuild.result = 'FAILURE'
echo "Exception thrown:\n ${err}"
echo 'Stacktrace:'
err.printStackTrace()
}
postBuildActions()
}
if (isMainRun) {
// Only run FOSSA on main runs.
builders['FOSSA'] = {
retryPodTemplate('fossa', [gcloudContainer(), pxdevContainer()]) {
fetchSourceK8s {
container('pxdev') {
warnError('FOSSA command failed') {
withCredentials([
string(
credentialsId: 'fossa-api-key',
variable: 'FOSSA_API_KEY'
)
]) {
sh 'git config --global --add safe.directory `pwd`'
sh 'fossa analyze --branch main'
}
}
}
}
}
}
}
builders['Lint & Docs'] = {
pxbuildWithSourceAndTargetsK8s('lint') {
container('pxbuild') {
// Prototool relies on having a main branch in this checkout, so create one tracking origin/main
sh 'git branch main --track origin/main'
sh 'arc lint --trace --never-apply-patches'
}
}
}
/*****************************************************************************
* END BUILDERS
*****************************************************************************/
def archiveBuildArtifacts = {
retryPodTemplate('archive', [gcloudContainer()]) {
container('gcloud') {
// Unstash the build artifacts.
stashList.each { stashName ->
dir(stashName) {
unstashFromGCS(stashName)
}
}
// Remove the tests attempts directory because it
// causes the test publisher to mark as failed.
sh 'find . -name test_attempts -type d -exec rm -rf {} +'
// Archive clang-tidy logs.
archiveArtifacts artifacts: 'build-clang-tidy-logs/**', fingerprint: true, allowEmptyArchive: true
// Actually process the bazel logs to look for test failures.
processAllExtractedBazelLogs()
}
}
}
/********************************************
* The build script starts here.
********************************************/
def buildScriptForCommits = {
retryPodTemplate('root', [gcloudContainer()]) {
if (isMainRun || isOSSMainRun) {
def namePrefix = 'pixie-main'
if (isOSSMainRun) {
namePrefix = 'pixie-oss'
}
// If there is a later build queued up, we want to stop the current build so
// we can execute the later build instead.
def q = Jenkins.get().getQueue()
abortBuild = false
q.getItems().each {
if (it.task.getDisplayName() == 'build-and-test-all') {
// Use fullDisplayName to distinguish between pixie-oss and pixie-main builds.
if (it.task.getFullDisplayName().startsWith(namePrefix)) {
abortBuild = true
}
}
}
if (abortBuild) {
echo 'Stopping current build because a later build is already enqueued'
return
}
}
try {
stage('Checkout code') {
checkoutAndInitialize()
}
stage('Pre-Build') {
parallel(preBuild)
}
stage('Build Steps') {
parallel(builders)
}
stage('Archive') {
archiveBuildArtifacts()
}
}
catch (err) {
currentBuild.result = 'FAILURE'
echo "Exception thrown:\n ${err}"
echo 'Stacktrace:'
err.printStackTrace()
}
postBuildActions()
}
}
/*****************************************************************************
* REGRESSION_BUILDERS: This sections defines all the test regressions steps
* that will happen in parallel.
*****************************************************************************/
def bpfRegressionBuilders = [:]
BPF_KERNELS.each { kernel ->
bpfRegressionBuilders["Test (opt) ${kernel}"] = {
retryPodTemplate('build-bpf-opt', [gcloudContainer()]) {
fetchSourceAndTargetsK8s {
container('gcloud') {
bazelCICmdBPFonGCE('build-bpf', 'bpf', 'opt', 'bpf', '', kernel)
}
}
}
}
}
/*****************************************************************************
* REGRESSION_BUILDERS: This sections defines all the test regressions steps
* that will happen in parallel.
*****************************************************************************/
def regressionBuilders = [:]
TEST_ITERATIONS = 5
regressionBuilders['Test (opt)'] = {
pxbuildWithSourceAndTargetsK8s('test-opt') {
container('pxbuild') {
bazelCICmd('build-opt', 'clang', 'opt', 'clang_opt', "--runs_per_test ${TEST_ITERATIONS}")
}
}
}
regressionBuilders['Test (ASAN)'] = {
pxbuildWithSourceAndTargetsK8s('test-asan') {
container('pxbuild') {
bazelCICmd('build-asan', 'asan', 'dbg', 'sanitizer', "--runs_per_test ${TEST_ITERATIONS}")
}
}
}
regressionBuilders['Test (TSAN)'] = {
pxbuildWithSourceAndTargetsK8s('test-tsan') {
container('pxbuild') {
bazelCICmd('build-tsan', 'tsan', 'dbg', 'sanitizer', "--runs_per_test ${TEST_ITERATIONS}")
}
}
}
/*****************************************************************************
* END REGRESSION_BUILDERS
*****************************************************************************/
/*****************************************************************************
* STIRLING PERF BUILDERS: Create & deploy, wait, then measure CPU use.
*****************************************************************************/
def clusterNames = (params.CLUSTER_NAMES != null) ? params.CLUSTER_NAMES.split(',') : ['']
int numPerfEvals = (params.NUM_EVAL_RUNS != null) ? Integer.parseInt(params.NUM_EVAL_RUNS) : 5
int warmupMinutes = (params.WARMUP_MINUTES != null) ? Integer.parseInt(params.WARMUP_MINUTES) : 30
int evalMinutes = (params.EVAL_MINUTES != null) ? Integer.parseInt(params.EVAL_MINUTES) : 60
int profilerMinutes = (params.PROFILER_MINUTES != null) ? Integer.parseInt(params.PROFILER_MINUTES) : 5
int cleanupClusters = (params.CLEANUP_CLUSTERS != null) ? Integer.parseInt(params.CLEANUP_CLUSTERS) : 1
String groupName = (params.GROUP_NAME != null) ? params.GROUP_NAME : 'none'
String machineType = (params.MACHINE_TYPE != null) ? params.MACHINE_TYPE : 'n2-standard-4'
String experimentTag = (params.EXPERIMENT_TAG != null) ? params.EXPERIMENT_TAG : 'none'
String gitHashForPerfEval = (params.GIT_HASH_FOR_PERF_EVAL != null) ? params.GIT_HASH_FOR_PERF_EVAL : 'HEAD'
String imageTagForPerfEval = 'none'
def stirlingPerfBuilders = [:]
String getClusterNameDateString() {
date = LocalDateTime.now()
return date.format(DateTimeFormatter.ofPattern('yyyy-MM-dd-HH-mm-ss'))
}
useCluster = { String clusterName ->
sh 'hostname'
sh 'gcloud --version'
sh "gcloud container clusters get-credentials ${clusterName} --project pl-pixies --zone us-west1-a"
}
deleteCluster = { String clusterName ->
// We use 'delete || true' so that failure does not cause the entire pipeline to fail or go unstable.
// In particular, deleteCluster is invoked when createCluster fails; this has two scenarios:
// 1. The cluster was created, but the gcloud command failed anyway.
// 2. The cluster was not created.
// ... For (1) above, we expect cluster deletion to succeed.
// ... For (2) above, we invoke deleteCluster (because it is hard to know we are in this scenario),
// ... and we expect the command to fail, but we don't want the entire build/perf-eval to stop.
// In general, if clusters leak through, they are eventually cleaned up by the perf eval cluster
// cleanup cron job.
sh "gcloud container --project pl-pixies clusters delete ${clusterName} --zone us-west1-a --quiet || true"
}
createCluster = { String clusterName ->
retryIdx = 0
numRetries = 3
// We will uniquify the cluster name based on the retry count because there is some chance
// that gcloud will refuse to create a cluster (on retry) based on a name being in use.
// Here we create a local variable 'retryUniqueClusterName' that is distinct from 'clusterName'
// because 'clusterName' is curried into 'oneEval'. If we clobber 'clusterName' here,
// the currying becomes wrong and different evals will wrongly all pick up the same cluster name.
retryUniqueClusterName = null
createClusterScript = 'scripts/create_gke_cluster.sh'
sh 'hostname'
sh 'gcloud components update'
sh 'gcloud --version'
retry(numRetries) {
if (retryIdx > 0) {
// Prevent leaking clusters from previous attempts.
deleteCluster(retryUniqueClusterName)
}
// Uniquify the cluster name based on the retryIdx because retry attempts
// may fail based on the pre-existing cluster name.
retryUniqueClusterName = clusterName + '-' + String.format('%d', retryIdx)
sh "${createClusterScript} -S -f -n 1 -c ${retryUniqueClusterName} -m ${machineType}"
++retryIdx
}
}
pxDeployForStirlingPerfEval = {
withCredentials([
string(
// There are two credentials for perf-evals:
// 1. px-staging-user-api-key: staging cloud as pixie org. member.
// 2. px-stirling-perf-eval-user-api-key: staging cloud, as "perf-eval" (a different) org.
// Currently using (2) above because that isolates the perf evals from updates made to staging
// cloud by the cloud team, e.g. plugin scripts running (or not running).
credentialsId: 'px-stirling-perf-eval-user-api-key',
variable: 'THE_PIXIE_CLI_API_KEY'
)
]) {
withEnv(['PL_CLOUD_ADDR=staging.withpixie.dev:443']) {
// Useful if one wants to ssh in for debugging "Jenkins only" issues.
sh 'hostname'
// Download the latest px binary.
// Deploy demo apps.
// Deploy pixie.
sh 'curl -fsSL https://storage.googleapis.com/pixie-dev-public/cli/latest/cli_linux_amd64 -o /usr/local/bin/px'
sh 'chmod +x /usr/local/bin/px'
sh 'px auth login --use_api_key --api_key ${THE_PIXIE_CLI_API_KEY}'
sh 'px demo deploy px-kafka -y -q'
sh 'px demo deploy px-sock-shop -y -q'
sh 'px demo deploy px-online-boutique -y -q'
sh 'px deploy -y -q'
// Ensure skaffold is configured with the dev. image registry.
sh 'skaffold config set default-repo gcr.io/pl-dev-infra'
// Regenerate the json list of artifacts targeting the images built for this eval.
sh "skaffold build -p opt -t ${imageTagForPerfEval} --dry-run -q -f skaffold/skaffold_vizier.yaml > artifacts.json"
// Useful for local debug, or to verify the image tags.
sh 'cat artifacts.json'
// Skaffold deploy using perf-eval images generated in the build & push step.
sh 'cat artifacts.json | skaffold deploy -f skaffold/skaffold_vizier.yaml --build-artifacts -'
}
}
}
def pxCollectPerfInfo(String clusterName, int evalIdx, int evalMinutes, int profilerMinutes) {
withCredentials([
string(
credentialsId: 'px-stirling-perf-eval-user-api-key',
variable: 'THE_PIXIE_CLI_API_KEY'
)
]) {
withEnv(['PL_CLOUD_ADDR=staging.withpixie.dev:443']) {
// These should have been created when un-stashing the repo info.
assert fileExists('logs')
assert fileExists('logs/pod_resource_usage')
// Show the cluster name (useful if results are strange and we suspect the wrong
// cluster was used for recording perf info).
sh 'kubectl config current-context'