From b8e3dd8fa0779b75459574c4a4e8ba552eb26d10 Mon Sep 17 00:00:00 2001 From: "stonezdj(Daojun Zhang)" Date: Thu, 26 Jun 2025 14:05:02 +0800 Subject: [PATCH 1/4] change the pass-CI rules to exclude the resources and robot-cases folder (#22121) Change the pass-CI rules to exclude the resources and robot-cases folder Pass HARBOR_ADMIN env to robot testcases Signed-off-by: stonezdj --- .github/workflows/pass-CI.yml | 4 ++++ tests/ci/api_run.sh | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pass-CI.yml b/.github/workflows/pass-CI.yml index 24049ba7d9..d335d1b96e 100644 --- a/.github/workflows/pass-CI.yml +++ b/.github/workflows/pass-CI.yml @@ -9,6 +9,8 @@ on: - '!tests/**.sh' - '!tests/apitests/**' - '!tests/ci/**' + - '!tests/resources/**' + - '!tests/robot-cases/**' push: paths: - 'docs/**' @@ -17,6 +19,8 @@ on: - '!tests/**.sh' - '!tests/apitests/**' - '!tests/ci/**' + - '!tests/resources/**' + - '!tests/robot-cases/**' jobs: UTTEST: diff --git a/tests/ci/api_run.sh b/tests/ci/api_run.sh index b348ea2ac6..498e405795 100755 --- a/tests/ci/api_run.sh +++ b/tests/ci/api_run.sh @@ -20,9 +20,9 @@ set +e docker ps # run db auth api cases if [ "$1" = 'DB' ]; then - docker run -i --privileged -v $DIR/../../:/drone -v $DIR/../:/ca -w /drone $E2E_IMAGE robot --exclude proxy_cache -v DOCKER_USER:${DOCKER_USER} -v DOCKER_PWD:${DOCKER_PWD} -v ip:$2 -v ip1: -v http_get_ca:false -v HARBOR_PASSWORD:Harbor12345 /drone/tests/robot-cases/Group1-Nightly/Setup.robot /drone/tests/robot-cases/Group0-BAT/API_DB.robot + docker run -i --privileged -v $DIR/../../:/drone -v $DIR/../:/ca -w /drone $E2E_IMAGE robot --exclude proxy_cache -v DOCKER_USER:"${DOCKER_USER}" -v DOCKER_PWD:${DOCKER_PWD} -v ip:$2 -v ip1: -v http_get_ca:false -v HARBOR_PASSWORD:${HARBOR_ADMIN_PASSWD} -v HARBOR_ADMIN:${HARBOR_ADMIN} /drone/tests/robot-cases/Group1-Nightly/Setup.robot /drone/tests/robot-cases/Group0-BAT/API_DB.robot elif [ "$1" = 'PROXY_CACHE' ]; then - docker run -i --privileged -v $DIR/../../:/drone -v $DIR/../:/ca -w /drone $E2E_IMAGE robot --include setup --include proxy_cache -v DOCKER_USER:${DOCKER_USER} -v DOCKER_PWD:${DOCKER_PWD} -v ip:$2 -v ip1: -v http_get_ca:false -v HARBOR_PASSWORD:Harbor12345 /drone/tests/robot-cases/Group1-Nightly/Setup.robot /drone/tests/robot-cases/Group0-BAT/API_DB.robot + docker run -i --privileged -v $DIR/../../:/drone -v $DIR/../:/ca -w /drone $E2E_IMAGE robot --include setup --include proxy_cache -v DOCKER_USER:"${DOCKER_USER}" -v DOCKER_PWD:${DOCKER_PWD} -v ip:$2 -v ip1: -v http_get_ca:false -v HARBOR_PASSWORD:${HARBOR_ADMIN_PASSWD} -v HARBOR_ADMIN:${HARBOR_ADMIN} /drone/tests/robot-cases/Group1-Nightly/Setup.robot /drone/tests/robot-cases/Group0-BAT/API_DB.robot elif [ "$1" = 'LDAP' ]; then # run ldap api cases python $DIR/../../tests/configharbor.py -H $IP -u $HARBOR_ADMIN -p $HARBOR_ADMIN_PASSWD -c auth_mode=ldap_auth \ @@ -31,7 +31,7 @@ elif [ "$1" = 'LDAP' ]; then ldap_search_password=admin \ ldap_base_dn=dc=example,dc=com \ ldap_uid=cn - docker run -i --privileged -v $DIR/../../:/drone -v $DIR/../:/ca -w /drone $E2E_IMAGE robot -v DOCKER_USER:${DOCKER_USER} -v DOCKER_PWD:${DOCKER_PWD} -v ip:$2 -v ip1: -v http_get_ca:false -v HARBOR_PASSWORD:Harbor12345 /drone/tests/robot-cases/Group1-Nightly/Setup.robot /drone/tests/robot-cases/Group0-BAT/API_LDAP.robot + docker run -i --privileged -v $DIR/../../:/drone -v $DIR/../:/ca -w /drone $E2E_IMAGE robot -v DOCKER_USER:"${DOCKER_USER}" -v DOCKER_PWD:${DOCKER_PWD} -v ip:$2 -v ip1: -v http_get_ca:false -v HARBOR_PASSWORD:${HARBOR_ADMIN_PASSWD} -v HARBOR_ADMIN:${HARBOR_ADMIN} /drone/tests/robot-cases/Group1-Nightly/Setup.robot /drone/tests/robot-cases/Group0-BAT/API_LDAP.robot else rc=999 fi From 0c5d82e9d497ab3778a6ccac63cdf4ee1a8fd66f Mon Sep 17 00:00:00 2001 From: miner Date: Tue, 1 Jul 2025 14:23:05 +0800 Subject: [PATCH 2/4] Update pipenv for prepare (#22124) * update pipenv and lock Signed-off-by: my036811 * update pipenv Signed-off-by: my036811 --------- Signed-off-by: my036811 --- make/photon/prepare/Dockerfile.base | 2 +- make/photon/prepare/Pipfile | 2 +- make/photon/prepare/Pipfile.lock | 165 +++++++++++----------------- 3 files changed, 67 insertions(+), 102 deletions(-) diff --git a/make/photon/prepare/Dockerfile.base b/make/photon/prepare/Dockerfile.base index e88bbb7da0..3df3256c9b 100644 --- a/make/photon/prepare/Dockerfile.base +++ b/make/photon/prepare/Dockerfile.base @@ -1,7 +1,7 @@ FROM photon:5.0 RUN tdnf install -y python3 python3-pip python3-PyYAML python3-jinja2 && tdnf clean all -RUN pip3 install pipenv==2022.1.8 +RUN pip3 install pipenv==2025.0.3 #To install only htpasswd binary from photon package httpd RUN tdnf install -y rpm cpio apr-util diff --git a/make/photon/prepare/Pipfile b/make/photon/prepare/Pipfile index 61b85654f9..efea2909bf 100644 --- a/make/photon/prepare/Pipfile +++ b/make/photon/prepare/Pipfile @@ -12,4 +12,4 @@ pylint = "*" pytest = "*" [requires] -python_version = "3.9.1" +python_version = "3.13" diff --git a/make/photon/prepare/Pipfile.lock b/make/photon/prepare/Pipfile.lock index c087da9402..6856b3f634 100644 --- a/make/photon/prepare/Pipfile.lock +++ b/make/photon/prepare/Pipfile.lock @@ -1,11 +1,11 @@ { "_meta": { "hash": { - "sha256": "0c84f574a48755d88f78a64d754b3f834a72f2a86808370dd5f3bf3e650bfa13" + "sha256": "d3a89b8575c29b9f822b892ffd31fd4a997effb1ebf3e3ed061a41e2d04b4490" }, "pipfile-spec": 6, "requires": { - "python_version": "3.9.1" + "python_version": "3.13" }, "sources": [ { @@ -18,157 +18,122 @@ "default": { "click": { "hashes": [ - "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a", - "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6" + "sha256:27c491cc05d968d271d5a1db13e3b5a184636d9d930f148c50b038f0d0646202", + "sha256:61a3265b914e850b85317d0b3109c7f8cd35a670f963866005d6ef1d5175a12b" ], "index": "pypi", - "version": "==8.0.1" + "markers": "python_version >= '3.10'", + "version": "==8.2.1" }, "packaging": { "hashes": [ - "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5", - "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a" + "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", + "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f" ], "index": "pypi", - "version": "==20.9" - }, - "pyparsing": { - "hashes": [ - "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1", - "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b" - ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.4.7" + "markers": "python_version >= '3.8'", + "version": "==25.0" } }, "develop": { "astroid": { "hashes": [ - "sha256:4db03ab5fc3340cf619dbc25e42c2cc3755154ce6009469766d7143d1fc2ee4e", - "sha256:8a398dfce302c13f14bab13e2b14fe385d32b73f4e4853b9bdfb64598baa1975" + "sha256:104fb9cb9b27ea95e847a94c003be03a9e039334a8ebca5ee27dafaf5c5711eb", + "sha256:c332157953060c6deb9caa57303ae0d20b0fbdb2e59b4a4f2a6ba49d0a7961ce" ], - "markers": "python_version ~= '3.6'", - "version": "==2.5.6" + "markers": "python_full_version >= '3.9.0'", + "version": "==3.3.10" }, - "attrs": { + "dill": { "hashes": [ - "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1", - "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb" + "sha256:0633f1d2df477324f53a895b02c901fb961bdbf65a17122586ea7019292cbcf0", + "sha256:44f54bf6412c2c8464c14e8243eb163690a9800dbe2c367330883b19c7561049" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", - "version": "==21.2.0" + "markers": "python_version >= '3.8'", + "version": "==0.4.0" }, "iniconfig": { "hashes": [ - "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3", - "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32" + "sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7", + "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760" ], - "version": "==1.1.1" + "markers": "python_version >= '3.8'", + "version": "==2.1.0" }, "isort": { "hashes": [ - "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6", - "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d" + "sha256:1cb5df28dfbc742e490c5e41bad6da41b805b0a8be7bc93cd0fb2a8a890ac450", + "sha256:2dc5d7f65c9678d94c88dfc29161a320eec67328bc97aad576874cb4be1e9615" ], - "markers": "python_version >= '3.6' and python_version < '4.0'", - "version": "==5.8.0" - }, - "lazy-object-proxy": { - "hashes": [ - "sha256:17e0967ba374fc24141738c69736da90e94419338fd4c7c7bef01ee26b339653", - "sha256:1fee665d2638491f4d6e55bd483e15ef21f6c8c2095f235fef72601021e64f61", - "sha256:22ddd618cefe54305df49e4c069fa65715be4ad0e78e8d252a33debf00f6ede2", - "sha256:24a5045889cc2729033b3e604d496c2b6f588c754f7a62027ad4437a7ecc4837", - "sha256:410283732af311b51b837894fa2f24f2c0039aa7f220135192b38fcc42bd43d3", - "sha256:4732c765372bd78a2d6b2150a6e99d00a78ec963375f236979c0626b97ed8e43", - "sha256:489000d368377571c6f982fba6497f2aa13c6d1facc40660963da62f5c379726", - "sha256:4f60460e9f1eb632584c9685bccea152f4ac2130e299784dbaf9fae9f49891b3", - "sha256:5743a5ab42ae40caa8421b320ebf3a998f89c85cdc8376d6b2e00bd12bd1b587", - "sha256:85fb7608121fd5621cc4377a8961d0b32ccf84a7285b4f1d21988b2eae2868e8", - "sha256:9698110e36e2df951c7c36b6729e96429c9c32b3331989ef19976592c5f3c77a", - "sha256:9d397bf41caad3f489e10774667310d73cb9c4258e9aed94b9ec734b34b495fd", - "sha256:b579f8acbf2bdd9ea200b1d5dea36abd93cabf56cf626ab9c744a432e15c815f", - "sha256:b865b01a2e7f96db0c5d12cfea590f98d8c5ba64ad222300d93ce6ff9138bcad", - "sha256:bf34e368e8dd976423396555078def5cfc3039ebc6fc06d1ae2c5a65eebbcde4", - "sha256:c6938967f8528b3668622a9ed3b31d145fab161a32f5891ea7b84f6b790be05b", - "sha256:d1c2676e3d840852a2de7c7d5d76407c772927addff8d742b9808fe0afccebdf", - "sha256:d7124f52f3bd259f510651450e18e0fd081ed82f3c08541dffc7b94b883aa981", - "sha256:d900d949b707778696fdf01036f58c9876a0d8bfe116e8d220cfd4b15f14e741", - "sha256:ebfd274dcd5133e0afae738e6d9da4323c3eb021b3e13052d8cbd0e457b1256e", - "sha256:ed361bb83436f117f9917d282a456f9e5009ea12fd6de8742d1a4752c3017e93", - "sha256:f5144c75445ae3ca2057faac03fda5a902eff196702b0a24daf1d6ce0650514b" - ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'", - "version": "==1.6.0" + "markers": "python_full_version >= '3.9.0'", + "version": "==6.0.1" }, "mccabe": { "hashes": [ - "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", - "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f" + "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325", + "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e" ], - "version": "==0.6.1" + "markers": "python_version >= '3.6'", + "version": "==0.7.0" }, "packaging": { "hashes": [ - "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5", - "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a" + "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", + "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f" ], "index": "pypi", - "version": "==20.9" + "markers": "python_version >= '3.8'", + "version": "==25.0" + }, + "platformdirs": { + "hashes": [ + "sha256:3d512d96e16bcb959a814c9f348431070822a6496326a4be0911c40b5a74c2bc", + "sha256:ff7059bb7eb1179e2685604f4aaf157cfd9535242bd23742eadc3c13542139b4" + ], + "markers": "python_version >= '3.9'", + "version": "==4.3.8" }, "pluggy": { "hashes": [ - "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0", - "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d" + "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", + "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.13.1" + "markers": "python_version >= '3.9'", + "version": "==1.6.0" }, - "py": { + "pygments": { "hashes": [ - "sha256:21b81bda15b66ef5e1a777a21c4dcd9c20ad3efd0b3f817e7a809035269e1bd3", - "sha256:3b80836aa6d1feeaa108e046da6423ab8f6ceda6468545ae8d02d9d58d18818a" + "sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887", + "sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.10.0" + "markers": "python_version >= '3.8'", + "version": "==2.19.2" }, "pylint": { "hashes": [ - "sha256:586d8fa9b1891f4b725f587ef267abe2a1bad89d6b184520c7f07a253dd6e217", - "sha256:f7e2072654a6b6afdf5e2fb38147d3e2d2d43c89f648637baab63e026481279b" + "sha256:2b11de8bde49f9c5059452e0c310c079c746a0a8eeaa789e5aa966ecc23e4559", + "sha256:43860aafefce92fca4cf6b61fe199cdc5ae54ea28f9bf4cd49de267b5195803d" ], "index": "pypi", - "version": "==2.8.2" - }, - "pyparsing": { - "hashes": [ - "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1", - "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b" - ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.4.7" + "markers": "python_full_version >= '3.9.0'", + "version": "==3.3.7" }, "pytest": { "hashes": [ - "sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b", - "sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890" + "sha256:539c70ba6fcead8e78eebbf1115e8b589e7565830d7d006a8723f19ac8a0afb7", + "sha256:7c67fd69174877359ed9371ec3af8a3d2b04741818c51e5e99cc1742251fa93c" ], "index": "pypi", - "version": "==6.2.4" + "markers": "python_version >= '3.9'", + "version": "==8.4.1" }, - "toml": { + "tomlkit": { "hashes": [ - "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b", - "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f" + "sha256:430cf247ee57df2b94ee3fbe588e71d362a941ebb545dec29b53961d61add2a1", + "sha256:c89c649d79ee40629a9fda55f8ace8c6a1b42deb912b2a8fd8d942ddadb606b0" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.10.2" - }, - "wrapt": { - "hashes": [ - "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7" - ], - "version": "==1.12.1" + "markers": "python_version >= '3.8'", + "version": "==0.13.3" } } } From 0f8913bb275b8975684a7e4fee87f689d1ed4f1c Mon Sep 17 00:00:00 2001 From: Chlins Zhang Date: Tue, 1 Jul 2025 15:33:05 +0800 Subject: [PATCH 3/4] feat: support customize the job execution retention count by env (#22129) Signed-off-by: chlins --- src/jobservice/job/known_jobs.go | 28 ++++++----- src/lib/env.go | 35 ++++++++++++++ src/lib/env_test.go | 83 ++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 src/lib/env.go create mode 100644 src/lib/env_test.go diff --git a/src/jobservice/job/known_jobs.go b/src/jobservice/job/known_jobs.go index 3572e49571..1bd0ccd700 100644 --- a/src/jobservice/job/known_jobs.go +++ b/src/jobservice/job/known_jobs.go @@ -14,6 +14,8 @@ package job +import "github.com/goharbor/harbor/src/lib" + // Define the register name constants of known jobs const ( @@ -53,19 +55,19 @@ const ( var ( // executionSweeperCount stores the count for execution retained executionSweeperCount = map[string]int64{ - ImageScanJobVendorType: 1, - SBOMJobVendorType: 1, - ScanAllVendorType: 1, - PurgeAuditVendorType: 10, - ExecSweepVendorType: 10, - GarbageCollectionVendorType: 50, - SlackJobVendorType: 50, - WebhookJobVendorType: 50, - ReplicationVendorType: 50, - ScanDataExportVendorType: 50, - SystemArtifactCleanupVendorType: 50, - P2PPreheatVendorType: 50, - RetentionVendorType: 50, + ImageScanJobVendorType: lib.GetEnvInt64("IMAGE_SCAN_EXECUTION_RETENTION_COUNT", 1), + SBOMJobVendorType: lib.GetEnvInt64("SBOM_EXECUTION_RETENTION_COUNT", 1), + ScanAllVendorType: lib.GetEnvInt64("SCAN_ALL_EXECUTION_RETENTION_COUNT", 1), + PurgeAuditVendorType: lib.GetEnvInt64("PURGE_AUDIT_EXECUTION_RETENTION_COUNT", 10), + ExecSweepVendorType: lib.GetEnvInt64("EXECUTION_SWEEP_EXECUTION_RETENTION_COUNT", 10), + GarbageCollectionVendorType: lib.GetEnvInt64("GARBAGE_COLLECTION_EXECUTION_RETENTION_COUNT", 50), + SlackJobVendorType: lib.GetEnvInt64("SLACK_EXECUTION_RETENTION_COUNT", 50), + WebhookJobVendorType: lib.GetEnvInt64("WEBHOOK_EXECUTION_RETENTION_COUNT", 50), + ReplicationVendorType: lib.GetEnvInt64("REPLICATION_EXECUTION_RETENTION_COUNT", 50), + ScanDataExportVendorType: lib.GetEnvInt64("SCAN_DATA_EXPORT_EXECUTION_RETENTION_COUNT", 50), + SystemArtifactCleanupVendorType: lib.GetEnvInt64("SYSTEM_ARTIFACT_CLEANUP_EXECUTION_RETENTION_COUNT", 50), + P2PPreheatVendorType: lib.GetEnvInt64("P2P_PREHEAT_EXECUTION_RETENTION_COUNT", 50), + RetentionVendorType: lib.GetEnvInt64("RETENTION_EXECUTION_RETENTION_COUNT", 50), } ) diff --git a/src/lib/env.go b/src/lib/env.go new file mode 100644 index 0000000000..1c3b2f5309 --- /dev/null +++ b/src/lib/env.go @@ -0,0 +1,35 @@ +// Copyright Project Harbor Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package lib + +import ( + "os" + "strconv" +) + +// GetEnvInt64 reads an environment variable and converts it to an int64, returning the default value if not set or invalid. +func GetEnvInt64(envKey string, defaultValue int64) int64 { + value := os.Getenv(envKey) + if value == "" { + return defaultValue + } + + intValue, err := strconv.ParseInt(value, 10, 64) + if err != nil { + return defaultValue + } + + return intValue +} diff --git a/src/lib/env_test.go b/src/lib/env_test.go new file mode 100644 index 0000000000..45b772cb06 --- /dev/null +++ b/src/lib/env_test.go @@ -0,0 +1,83 @@ +package lib + +import ( + "os" + "testing" +) + +func TestGetEnvInt64(t *testing.T) { + tests := []struct { + name string + envKey string + envValue string + defaultValue int64 + setEnv bool + expectedValue int64 + }{ + { + name: "env set with valid value", + envKey: "TEST_ENV", + envValue: "100", + defaultValue: 50, + setEnv: true, + expectedValue: 100, + }, + { + name: "env not set", + envKey: "UNSET_ENV", + envValue: "", + defaultValue: 50, + setEnv: false, + expectedValue: 50, + }, + { + name: "env set with invalid value", + envKey: "INVALID_ENV", + envValue: "not_a_number", + defaultValue: 50, + setEnv: true, + expectedValue: 50, + }, + { + name: "env set with zero", + envKey: "ZERO_ENV", + envValue: "0", + defaultValue: 50, + setEnv: true, + expectedValue: 0, + }, + { + name: "env set with negative value", + envKey: "NEGATIVE_ENV", + envValue: "-10", + defaultValue: 50, + setEnv: true, + expectedValue: -10, + }, + { + name: "env set with large value", + envKey: "LARGE_ENV", + envValue: "9223372036854775807", + defaultValue: 50, + setEnv: true, + expectedValue: 9223372036854775807, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.setEnv { + os.Setenv(tt.envKey, tt.envValue) + } else { + os.Unsetenv(tt.envKey) + } + + result := GetEnvInt64(tt.envKey, tt.defaultValue) + if result != tt.expectedValue { + t.Errorf("GetEnvInt64(%q, %d) = %d; want %d", tt.envKey, tt.defaultValue, result, tt.expectedValue) + } + + os.Unsetenv(tt.envKey) + }) + } +} From 229ef886842b2f4ebd54bd8e2b273a45ec07df1d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 1 Jul 2025 08:19:14 +0000 Subject: [PATCH 4/4] chore(deps): bump github.com/volcengine/volcengine-go-sdk from 1.1.17 to 1.1.19 in /src (#22133) chore(deps): bump github.com/volcengine/volcengine-go-sdk in /src --- updated-dependencies: - dependency-name: github.com/volcengine/volcengine-go-sdk dependency-version: 1.1.19 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: miner --- src/go.mod | 2 +- src/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/go.mod b/src/go.mod index b5fbe4887d..a7c25faa3e 100644 --- a/src/go.mod +++ b/src/go.mod @@ -56,7 +56,7 @@ require ( github.com/stretchr/testify v1.10.0 github.com/tencentcloud/tencentcloud-sdk-go v3.0.233+incompatible github.com/vmihailenco/msgpack/v5 v5.4.1 - github.com/volcengine/volcengine-go-sdk v1.1.17 + github.com/volcengine/volcengine-go-sdk v1.1.19 go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux v0.59.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 go.opentelemetry.io/otel v1.35.0 diff --git a/src/go.sum b/src/go.sum index e60c68fcba..55263539a0 100644 --- a/src/go.sum +++ b/src/go.sum @@ -564,8 +564,8 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/volcengine/volc-sdk-golang v1.0.23 h1:anOslb2Qp6ywnsbyq9jqR0ljuO63kg9PY+4OehIk5R8= github.com/volcengine/volc-sdk-golang v1.0.23/go.mod h1:AfG/PZRUkHJ9inETvbjNifTDgut25Wbkm2QoYBTbvyU= -github.com/volcengine/volcengine-go-sdk v1.1.17 h1:Izrcx/FERzGvpY3ufPjt4GR7Ak6y94aMVXbnLmeuw2g= -github.com/volcengine/volcengine-go-sdk v1.1.17/go.mod h1:EyKoi6t6eZxoPNGr2GdFCZti2Skd7MO3eUzx7TtSvNo= +github.com/volcengine/volcengine-go-sdk v1.1.19 h1:+jLVMqDtdtiAt8QGBk6AMiEg22Br5SZGu2FSHUrIcU0= +github.com/volcengine/volcengine-go-sdk v1.1.19/go.mod h1:EyKoi6t6eZxoPNGr2GdFCZti2Skd7MO3eUzx7TtSvNo= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=