mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
[feat] - Introduce channelmetrics
Package for Channel Metrics Collection (#2889)
* Add pkg for channel metrics * Use map for different channel metrics * go mod tidy * use CacnellableWrite
This commit is contained in:
parent
c1a2019d5b
commit
aa91acc86b
5 changed files with 313 additions and 38 deletions
2
go.mod
2
go.mod
|
@ -255,7 +255,7 @@ require (
|
|||
github.com/shoenig/go-m1cpu v0.1.6 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/skeema/knownhosts v1.2.2 // indirect
|
||||
github.com/testcontainers/testcontainers-go/modules/redis v0.31.0 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/tetratelabs/wazero v1.7.1 // indirect
|
||||
github.com/therootcompany/xz v1.0.1 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||
|
|
38
go.sum
38
go.sum
|
@ -24,8 +24,6 @@ cloud.google.com/go/longrunning v0.5.7 h1:WLbHekDbjK1fVFD3ibpFFVoyizlLRl73I7YKuA
|
|||
cloud.google.com/go/longrunning v0.5.7/go.mod h1:8GClkudohy1Fxm3owmBGid8W0pSgodEMwEAztp38Xng=
|
||||
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
||||
cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
|
||||
cloud.google.com/go/secretmanager v1.13.0 h1:nQ/Ca2Gzm/OEP8tr1hiFdHRi5wAnAmsm9qTjwkivyrQ=
|
||||
cloud.google.com/go/secretmanager v1.13.0/go.mod h1:yWdfNmM2sLIiyv6RM6VqWKeBV7CdS0SO3ybxJJRhBEs=
|
||||
cloud.google.com/go/secretmanager v1.13.1 h1:TTGo2Vz7ZxYn2QbmuFP7Zo4lDm5VsbzBjDReo3SA5h4=
|
||||
cloud.google.com/go/secretmanager v1.13.1/go.mod h1:y9Ioh7EHp1aqEKGYXk3BOC+vkhlHm9ujL7bURT4oI/4=
|
||||
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
||||
|
@ -57,26 +55,19 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl
|
|||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs=
|
||||
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
|
||||
github.com/Azure/go-autorest/autorest v0.11.24 h1:1fIGgHKqVm54KIPT+q8Zmd1QlVsmHqeUGso5qm2BqqE=
|
||||
github.com/Azure/go-autorest/autorest v0.11.24/go.mod h1:G6kyRlFnTuSbEYkQGawPfsCswgme4iYf6rfSKUDzbCc=
|
||||
github.com/Azure/go-autorest/autorest v0.11.28 h1:ndAExarwr5Y+GaHE6VCaY1kyS/HwwGGyuimVhWsHOEM=
|
||||
github.com/Azure/go-autorest/autorest v0.11.28/go.mod h1:MrkzG3Y3AH668QyF9KRk5neJnGgmhQ6krbhR8Q5eMvA=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.9.18 h1:kLnPsRjzZZUF3K5REu/Kc+qMQrvuza2bwSnNdhmzLfQ=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.9.18/go.mod h1:XVVeme+LZwABT8K5Lc3hA4nAe8LDBVle26gTrguhhPQ=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.9.22 h1:/GblQdIudfEM3AWWZ0mrYJQSd7JS4S/Mbzh6F0ov0Xc=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.9.22/go.mod h1:XuAbAEUv2Tta//+voMI038TrJBqjKam0me7qR+L8Cmk=
|
||||
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12 h1:wkAZRgT/pn8HhFyzfe9UnqOjJYqlembgCTi72Bm/xKk=
|
||||
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12/go.mod h1:84w/uV8E37feW2NCJ08uT9VBfjfUHpgLVnG2InYD6cg=
|
||||
github.com/Azure/go-autorest/autorest/azure/auth v0.5.13 h1:Ov8avRZi2vmrE2JcXw+tu5K/yB41r7xK9GZDiBF7NdM=
|
||||
github.com/Azure/go-autorest/autorest/azure/auth v0.5.13/go.mod h1:5BAVfWLWXihP47vYrPuBKKf4cS0bXI+KM9Qx6ETDJYo=
|
||||
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 h1:0W/yGmFdTIT77fvdlGZ0LMISoLHFJ7Tx4U0yeB+uFs4=
|
||||
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5/go.mod h1:ADQAXrkgm7acgWVUNamOgh8YNrv4p27l3Wc55oVfpzg=
|
||||
github.com/Azure/go-autorest/autorest/azure/cli v0.4.6 h1:w77/uPk80ZET2F+AfQExZyEWtn+0Rk/uw17m9fv5Ajc=
|
||||
github.com/Azure/go-autorest/autorest/azure/cli v0.4.6/go.mod h1:piCfgPho7BiIDdEQ1+g4VmKyD5y+p/XtSNqE6Hc4QD0=
|
||||
github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw=
|
||||
github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.4.1 h1:K0laFcLE6VLTOwNgSxaGbUcLPuGXlNkbVvq4cW4nIHk=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.4.2 h1:PGN4EDXnuQbojHbU0UWoNvmu9AGVwYHG9/fkDYhtAfw=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.4.2/go.mod h1:Vy7OitM9Kei0i1Oj+LvyAWMXJHeKH1MVlzFugfVrmyU=
|
||||
github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+ZtXWSmf4Tg=
|
||||
github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8=
|
||||
|
@ -128,12 +119,6 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
|
|||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
|
||||
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/aws/aws-sdk-go v1.53.6 h1:1/MYh/VmxdJu7v2bwvDA2JS30UI7bg62QYgQ7KxMa/Q=
|
||||
github.com/aws/aws-sdk-go v1.53.6/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
|
||||
github.com/aws/aws-sdk-go v1.53.10 h1:3enP5l5WtezT9Ql+XZqs56JBf5YUd/FEzTCg///OIGY=
|
||||
github.com/aws/aws-sdk-go v1.53.10/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
|
||||
github.com/aws/aws-sdk-go v1.53.14 h1:SzhkC2Pzag0iRW8WBb80RzKdGXDydJR9LAMs2GyKJ2M=
|
||||
github.com/aws/aws-sdk-go v1.53.14/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
|
||||
github.com/aws/aws-sdk-go v1.53.15 h1:FtZmkg7xM8RfP2oY6p7xdKBYrRgkITk9yve2QV7N938=
|
||||
github.com/aws/aws-sdk-go v1.53.15/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
|
||||
github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw=
|
||||
|
@ -169,8 +154,6 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
|
|||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
|
||||
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
|
||||
github.com/charmbracelet/bubbletea v0.26.2 h1:Eeb+n75Om9gQ+I6YpbCXQRKHt5Pn4vMwusQpwLiEgJQ=
|
||||
github.com/charmbracelet/bubbletea v0.26.2/go.mod h1:6I0nZ3YHUrQj7YHIHlM8RySX4ZIthTliMY+W8X8b+Gs=
|
||||
github.com/charmbracelet/bubbletea v0.26.4 h1:2gDkkzLZaTjMl/dQBpNVtnvcCxsh/FCkimep7FC9c40=
|
||||
github.com/charmbracelet/bubbletea v0.26.4/go.mod h1:P+r+RRA5qtI1DOHNFn0otoNwB4rn+zNAzSj/EXz6xU0=
|
||||
github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng=
|
||||
|
@ -258,8 +241,6 @@ github.com/dvsekhvalnov/jose2go v1.6.0 h1:Y9gnSnP4qEI0+/uQkHvFXeD2PLPJeXEL+ySMEA
|
|||
github.com/dvsekhvalnov/jose2go v1.6.0/go.mod h1:QsHjhyTlD/lAVqn/NSbVZmSCGeDehTB/mPZadG+mhXU=
|
||||
github.com/elastic/elastic-transport-go/v8 v8.5.0 h1:v5membAl7lvQgBTexPRDBO/RdnlQX+FM9fUVDyXxvH0=
|
||||
github.com/elastic/elastic-transport-go/v8 v8.5.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
|
||||
github.com/elastic/go-elasticsearch/v8 v8.13.0 h1:YXPAWpvbYX0mWSNG9tnEpvs4h1stgMy5JUeKZECYYB8=
|
||||
github.com/elastic/go-elasticsearch/v8 v8.13.0/go.mod h1:DIn7HopJs4oZC/w0WoJR13uMUxtHeq92eI5bqv5CRfI=
|
||||
github.com/elastic/go-elasticsearch/v8 v8.13.1 h1:du5F8IzUUyCkzxyHdrO9AtopcG95I/qwi2WK8Kf1xlg=
|
||||
github.com/elastic/go-elasticsearch/v8 v8.13.1/go.mod h1:DIn7HopJs4oZC/w0WoJR13uMUxtHeq92eI5bqv5CRfI=
|
||||
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU=
|
||||
|
@ -286,8 +267,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
|
|||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
|
||||
github.com/gabriel-vasile/mimetype v1.4.4/go.mod h1:JwLei5XPtWdGiMFB5Pjle1oEeoSeEuJfJE+TtfvdB/s=
|
||||
github.com/getsentry/sentry-go v0.27.0 h1:Pv98CIbtB3LkMWmXi4Joa5OOcwbmnX88sF5qbK3r3Ps=
|
||||
|
@ -313,8 +292,6 @@ github.com/go-ldap/ldap/v3 v3.4.8 h1:loKJyspcRezt2Q3ZRMq2p/0v8iOurlmeXDPw6fikSvQ
|
|||
github.com/go-ldap/ldap/v3 v3.4.8/go.mod h1:qS3Sjlu76eHfHGpUdWkAXQTw4beih+cHsco2jXlIXrk=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
|
||||
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
|
@ -451,8 +428,6 @@ github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB1
|
|||
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
|
||||
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
|
||||
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.6 h1:TwRYfx2z2C4cLbXmT8I5PgP/xmuqASDyiVuGYfs9GZM=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.6/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
|
||||
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
|
||||
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
|
@ -579,8 +554,6 @@ github.com/mholt/archiver/v4 v4.0.0-alpha.8 h1:tRGQuDVPh66WCOelqe6LIGh0gwmfwxUrS
|
|||
github.com/mholt/archiver/v4 v4.0.0-alpha.8/go.mod h1:5f7FUYGXdJWUjESffJaYR4R60VhnHxb2X3T1teMyv5A=
|
||||
github.com/microcosm-cc/bluemonday v1.0.25 h1:4NEwSfiJ+Wva0VxN5B8OwMicaJvD8r9tlJWm9rtloEg=
|
||||
github.com/microcosm-cc/bluemonday v1.0.25/go.mod h1:ZIOjCQp1OrzBBPIJmfX4qDYFuhU02nx4bn030ixfHLE=
|
||||
github.com/microsoft/go-mssqldb v1.7.1 h1:KU/g8aWeM3Hx7IMOFpiwYiUkU+9zeISb4+tx3ScVfsM=
|
||||
github.com/microsoft/go-mssqldb v1.7.1/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA=
|
||||
github.com/microsoft/go-mssqldb v1.7.2 h1:CHkFJiObW7ItKTJfHo1QX7QBBD1iV+mn1eOyRP3b/PA=
|
||||
github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
|
@ -735,8 +708,6 @@ github.com/testcontainers/testcontainers-go/modules/mysql v0.31.0 h1:790+S8ewZYC
|
|||
github.com/testcontainers/testcontainers-go/modules/mysql v0.31.0/go.mod h1:REFmO+lSG9S6uSBEwIMZCxeI36uhScjTwChYADeO3JA=
|
||||
github.com/testcontainers/testcontainers-go/modules/postgres v0.31.0 h1:isAwFS3KNKRbJMbWv+wolWqOFUECmjYZ+sIRZCIBc/E=
|
||||
github.com/testcontainers/testcontainers-go/modules/postgres v0.31.0/go.mod h1:ZNYY8vumNCEG9YI59A9d6/YaMY49uwRhmeU563EzFGw=
|
||||
github.com/testcontainers/testcontainers-go/modules/redis v0.31.0 h1:5X6GhOdLwV86zcW8sxppJAMtsDC9u+r9tb3biBc9GKs=
|
||||
github.com/testcontainers/testcontainers-go/modules/redis v0.31.0/go.mod h1:dKi5xBwy1k4u8yb3saQHu7hMEJwewHXxzbcMAuLiA6o=
|
||||
github.com/tetratelabs/wazero v1.7.1 h1:QtSfd6KLc41DIMpDYlJdoMc6k7QTN246DM2+n2Y/Dx8=
|
||||
github.com/tetratelabs/wazero v1.7.1/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
|
||||
github.com/therootcompany/xz v1.0.1 h1:CmOtsn1CbtmyYiusbfmhmkpAAETj0wBIH6kCYaX+xzw=
|
||||
|
@ -844,7 +815,6 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
|
|||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
|
@ -863,10 +833,6 @@ golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE
|
|||
golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
|
||||
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
|
||||
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
|
||||
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d h1:N0hmiNbwsSNwHBAvR3QB5w25pUwH4tK0Y/RltD1j1h4=
|
||||
golang.org/x/exp v0.0.0-20240525044651-4c93da0ed11d/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
|
||||
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc h1:O9NuF4s+E/PvMIy+9IUZB9znFwUIXEWSstNjek6VpVg=
|
||||
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
|
@ -1095,8 +1061,6 @@ google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfG
|
|||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda h1:wu/KJm9KJwpfHWhkkZGohVC6KRrc1oJNr4jwtQMOQXw=
|
||||
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda/go.mod h1:g2LLCvCeCSir/JJSWosk19BR4NVxGqHUC6rxIRsd7Aw=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae h1:AH34z6WAGVNkllnKs5raNq3yRq93VnjBG6rpfub/jYk=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240506185236-b8a5c65736ae/go.mod h1:FfiGhwUm6CJviekPrc0oJ+7h29e+DmWU6UtjX0ZvI7Y=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 h1:W5Xj/70xIA4x60O/IFyXivR5MGqblAb8R3w26pnD6No=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8/go.mod h1:vPrPUTsDCYxXWjP7clS81mZ6/803D8K4iM9Ma27VKas=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240513163218-0867130af1f8 h1:mxSlqyb8ZAHsYDCfiXN1EDdNTdvjUJSLY+OnAUtYNYA=
|
||||
|
|
111
pkg/channelmetrics/metrics_collector/prometheus/collector.go
Normal file
111
pkg/channelmetrics/metrics_collector/prometheus/collector.go
Normal file
|
@ -0,0 +1,111 @@
|
|||
package prometheus
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
// MetricsCollector implements the |channelmetrics.MetricsCollector| interface using Prometheus.
|
||||
// It records various metrics related to channel operations.
|
||||
type MetricsCollector struct {
|
||||
produceDuration prometheus.Histogram
|
||||
consumeDuration prometheus.Histogram
|
||||
channelLen prometheus.Gauge
|
||||
channelCap prometheus.Gauge
|
||||
}
|
||||
|
||||
var (
|
||||
collectors = make(map[string]*MetricsCollector)
|
||||
collectorsMu sync.Mutex
|
||||
)
|
||||
|
||||
// NewMetricsCollector creates a new MetricsCollector with
|
||||
// histograms for produce and consume durations, and gauges for channel length and capacity.
|
||||
// It accepts namespace, subsystem, and chanName parameters to organize metrics.
|
||||
// The function initializes and returns a pointer to a MetricsCollector struct
|
||||
// that contains the following Prometheus metrics:
|
||||
//
|
||||
// - produceDuration: a Histogram metric that measures the duration of producing an item.
|
||||
// It tracks the time taken to add an item to the ObservableChan.
|
||||
// This metric helps to monitor the performance and latency of item production.
|
||||
//
|
||||
// - consumeDuration: a Histogram metric that measures the duration of consuming an item.
|
||||
// It tracks the time taken to retrieve an item from the ObservableChan.
|
||||
// This metric helps to monitor the performance and latency of item consumption.
|
||||
//
|
||||
// - channelLen: a Gauge metric that measures the current size of the channel buffer.
|
||||
// It tracks the number of items in the channel buffer at any given time.
|
||||
// This metric helps to monitor the utilization of the channel buffer.
|
||||
//
|
||||
// - channelCap: a Gauge metric that measures the capacity of the channel buffer.
|
||||
// It tracks the maximum number of items that the channel buffer can hold.
|
||||
// This metric helps to understand the configuration and potential limits of the channel buffer.
|
||||
//
|
||||
// These metrics are useful for monitoring the performance and throughput of the ObservableChan.
|
||||
// By tracking the durations of item production and consumption, as well as the buffer size and capacity,
|
||||
// you can identify bottlenecks, optimize performance, and ensure that the ObservableChan is operating efficiently.
|
||||
func NewMetricsCollector(chanName, namespace, subsystem string) *MetricsCollector {
|
||||
key := fmt.Sprintf("%s_%s_%s", namespace, subsystem, chanName)
|
||||
|
||||
collectorsMu.Lock()
|
||||
defer collectorsMu.Unlock()
|
||||
|
||||
if collector, exists := collectors[key]; exists {
|
||||
return collector
|
||||
}
|
||||
|
||||
collector := &MetricsCollector{
|
||||
produceDuration: promauto.NewHistogram(prometheus.HistogramOpts{
|
||||
Name: metricName(chanName, "produce_duration_microseconds"),
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Help: "Duration of producing an item in microseconds.",
|
||||
Buckets: prometheus.ExponentialBuckets(1, 2, 20),
|
||||
}),
|
||||
consumeDuration: promauto.NewHistogram(prometheus.HistogramOpts{
|
||||
Name: metricName(chanName, "consume_duration_microseconds"),
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Help: "Duration of consuming an item in microseconds.",
|
||||
Buckets: prometheus.ExponentialBuckets(1, 2, 20),
|
||||
}),
|
||||
channelLen: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: metricName(chanName, "channel_length"),
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Help: "Current size of the channel buffer.",
|
||||
}),
|
||||
channelCap: promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: metricName(chanName, "channel_capacity"),
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Help: "Capacity of the channel buffer.",
|
||||
}),
|
||||
}
|
||||
|
||||
collectors[key] = collector
|
||||
return collector
|
||||
}
|
||||
|
||||
// metricName constructs a full metric name by combining the channel name with the specific metric.
|
||||
func metricName(chanName, metric string) string { return chanName + "_" + metric }
|
||||
|
||||
// RecordProduceDuration records the duration taken to produce an item into the channel.
|
||||
func (c *MetricsCollector) RecordProduceDuration(duration time.Duration) {
|
||||
c.produceDuration.Observe(float64(duration.Microseconds()))
|
||||
}
|
||||
|
||||
// RecordConsumeDuration records the duration taken to consume an item from the channel.
|
||||
func (c *MetricsCollector) RecordConsumeDuration(duration time.Duration) {
|
||||
c.consumeDuration.Observe(float64(duration.Microseconds()))
|
||||
}
|
||||
|
||||
// RecordChannelLen records the current size of the channel buffer.
|
||||
func (c *MetricsCollector) RecordChannelLen(size int) { c.channelLen.Set(float64(size)) }
|
||||
|
||||
// RecordChannelCap records the capacity of the channel buffer.
|
||||
func (c *MetricsCollector) RecordChannelCap(capacity int) { c.channelCap.Set(float64(capacity)) }
|
84
pkg/channelmetrics/observablechan.go
Normal file
84
pkg/channelmetrics/observablechan.go
Normal file
|
@ -0,0 +1,84 @@
|
|||
// Package channelmetrics provides a flexible way to wrap Go channels with
|
||||
// additional metrics collection capabilities. This allows for monitoring
|
||||
// and tracking of channel usage and performance using different metrics backends.
|
||||
package channelmetrics
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
||||
)
|
||||
|
||||
// MetricsCollector is an interface for collecting metrics. Implementations
|
||||
// of this interface can be used to record various channel metrics.
|
||||
type MetricsCollector interface {
|
||||
RecordProduceDuration(duration time.Duration)
|
||||
RecordConsumeDuration(duration time.Duration)
|
||||
RecordChannelLen(size int)
|
||||
RecordChannelCap(capacity int)
|
||||
}
|
||||
|
||||
// ObservableChan wraps a Go channel and collects metrics about its usage.
|
||||
// It supports any type of channel and records metrics using a provided
|
||||
// MetricsCollector implementation.
|
||||
type ObservableChan[T any] struct {
|
||||
ch chan T
|
||||
metrics MetricsCollector
|
||||
bufferCap int
|
||||
}
|
||||
|
||||
// NewObservableChan creates a new ObservableChan wrapping the provided channel.
|
||||
// It records the channel's capacity immediately and sets up metrics collection
|
||||
// using the provided MetricsCollector and channel name. The chanName is used to
|
||||
// distinguish between metrics for different channels by incorporating it into
|
||||
// the metric names.
|
||||
func NewObservableChan[T any](ch chan T, metrics MetricsCollector) *ObservableChan[T] {
|
||||
oChan := &ObservableChan[T]{
|
||||
ch: ch,
|
||||
metrics: metrics,
|
||||
bufferCap: cap(ch),
|
||||
}
|
||||
oChan.RecordChannelCapacity() // Record capacity immediately
|
||||
return oChan
|
||||
}
|
||||
|
||||
// Close closes the channel and records the current size of the channel buffer.
|
||||
func (oc *ObservableChan[T]) Close() {
|
||||
close(oc.ch)
|
||||
oc.RecordChannelLen()
|
||||
}
|
||||
|
||||
// Send sends an item into the channel and records the duration taken to do so.
|
||||
// It also updates the current size of the channel buffer.
|
||||
func (oc *ObservableChan[T]) Send(ctx context.Context, item T) {
|
||||
startTime := time.Now()
|
||||
defer func() {
|
||||
oc.metrics.RecordProduceDuration(time.Since(startTime))
|
||||
oc.RecordChannelLen()
|
||||
}()
|
||||
if err := common.CancellableWrite(ctx, oc.ch, item); err != nil {
|
||||
ctx.Logger().Error(err, "failed to write item to observable channel")
|
||||
}
|
||||
}
|
||||
|
||||
// Recv receives an item from the channel and records the duration taken to do so.
|
||||
// It also updates the current size of the channel buffer.
|
||||
func (oc *ObservableChan[T]) Recv(_ context.Context) T {
|
||||
startTime := time.Now()
|
||||
defer func() {
|
||||
oc.metrics.RecordConsumeDuration(time.Since(startTime))
|
||||
oc.RecordChannelLen()
|
||||
}()
|
||||
return <-oc.ch
|
||||
}
|
||||
|
||||
// RecordChannelCapacity records the capacity of the channel buffer.
|
||||
func (oc *ObservableChan[T]) RecordChannelCapacity() {
|
||||
oc.metrics.RecordChannelCap(oc.bufferCap)
|
||||
}
|
||||
|
||||
// RecordChannelLen records the current size of the channel buffer.
|
||||
func (oc *ObservableChan[T]) RecordChannelLen() {
|
||||
oc.metrics.RecordChannelLen(len(oc.ch))
|
||||
}
|
116
pkg/channelmetrics/observablechan_test.go
Normal file
116
pkg/channelmetrics/observablechan_test.go
Normal file
|
@ -0,0 +1,116 @@
|
|||
package channelmetrics
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
||||
)
|
||||
|
||||
type MockMetricsCollector struct{ mock.Mock }
|
||||
|
||||
func (m *MockMetricsCollector) RecordProduceDuration(duration time.Duration) { m.Called(duration) }
|
||||
|
||||
func (m *MockMetricsCollector) RecordConsumeDuration(duration time.Duration) { m.Called(duration) }
|
||||
|
||||
func (m *MockMetricsCollector) RecordChannelLen(size int) { m.Called(size) }
|
||||
|
||||
func (m *MockMetricsCollector) RecordChannelCap(capacity int) { m.Called(capacity) }
|
||||
|
||||
func TestObservableChanSend(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mockMetrics := new(MockMetricsCollector)
|
||||
bufferCap := 10
|
||||
|
||||
mockMetrics.On("RecordProduceDuration", mock.Anything).Once()
|
||||
mockMetrics.On("RecordChannelLen", mock.AnythingOfType("int")).Once()
|
||||
mockMetrics.On("RecordChannelCap", bufferCap).Once()
|
||||
|
||||
ch := make(chan int, bufferCap)
|
||||
oc := NewObservableChan(ch, mockMetrics)
|
||||
assert.Equal(t, bufferCap, cap(oc.ch))
|
||||
|
||||
oc.Send(context.Background(), 1)
|
||||
|
||||
mockMetrics.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestObservableChanRecv(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mockMetrics := new(MockMetricsCollector)
|
||||
bufferCap := 10
|
||||
|
||||
mockMetrics.On("RecordConsumeDuration", mock.Anything).Once() // For the send
|
||||
mockMetrics.On("RecordProduceDuration", mock.Anything).Once()
|
||||
mockMetrics.On("RecordChannelLen", mock.AnythingOfType("int")).Twice() // For the send and recv
|
||||
mockMetrics.On("RecordChannelCap", bufferCap).Once()
|
||||
|
||||
ch := make(chan int, bufferCap)
|
||||
oc := NewObservableChan(ch, mockMetrics)
|
||||
assert.Equal(t, bufferCap, cap(oc.ch))
|
||||
|
||||
go func() {
|
||||
oc.Send(context.Background(), 1)
|
||||
}()
|
||||
|
||||
time.Sleep(100 * time.Millisecond) // Ensure Send happens before Recv
|
||||
|
||||
oc.Recv(context.Background())
|
||||
|
||||
mockMetrics.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestObservableChanRecordChannelCapacity(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mockMetrics := new(MockMetricsCollector)
|
||||
bufferCap := 10
|
||||
|
||||
mockMetrics.On("RecordChannelCap", bufferCap).Twice()
|
||||
|
||||
ch := make(chan int, bufferCap)
|
||||
oc := NewObservableChan(ch, mockMetrics)
|
||||
|
||||
oc.RecordChannelCapacity()
|
||||
|
||||
mockMetrics.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestObservableChanRecordChannelLen(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mockMetrics := new(MockMetricsCollector)
|
||||
bufferCap := 10
|
||||
|
||||
mockMetrics.On("RecordChannelLen", mock.AnythingOfType("int")).Once()
|
||||
mockMetrics.On("RecordChannelCap", bufferCap).Once()
|
||||
|
||||
ch := make(chan int, bufferCap)
|
||||
oc := NewObservableChan(ch, mockMetrics)
|
||||
|
||||
oc.RecordChannelLen()
|
||||
|
||||
mockMetrics.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestObservableChan_Close(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
mockMetrics := new(MockMetricsCollector)
|
||||
bufferCap := 1
|
||||
|
||||
mockMetrics.On("RecordChannelCap", bufferCap).Once()
|
||||
mockMetrics.On("RecordChannelLen", mock.AnythingOfType("int")).Once()
|
||||
|
||||
ch := make(chan int, bufferCap)
|
||||
oc := NewObservableChan(ch, mockMetrics)
|
||||
|
||||
oc.Close()
|
||||
|
||||
mockMetrics.AssertExpectations(t)
|
||||
}
|
Loading…
Reference in a new issue