Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:修复监控数据上报无法清理数据问题 #209

Merged
merged 8 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/activehealthcheck/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.3.2-alpha.2 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/activehealthcheck/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA=
github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
2 changes: 1 addition & 1 deletion examples/configuration/encrypt/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.4.0 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/configuration/encrypt/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.4.0 h1:fm7sUtFZC2g9+lLmRCtjGrUow47CY5JDFoZXwwCQGGY=
github.com/polarismesh/specification v1.4.0/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
2 changes: 1 addition & 1 deletion examples/quickstart/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}

func (svr *PolarisConsumer) runWebServer() {
http.HandleFunc("/echo", func(rw http.ResponseWriter, r *http.Request) {

Check warning on line 58 in examples/quickstart/consumer/main.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.18.x)

parameter 'r' seems to be unused, consider removing or renaming it as _
log.Printf("start to invoke getOneInstance operation")
// DiscoverEchoServer
getOneRequest := &polaris.GetOneInstanceRequest{}
Expand Down Expand Up @@ -92,7 +92,7 @@
},
}
ret.SetDelay(delay)
ret.SetRetCode(int32(resp.StatusCode))
ret.SetRetCode(int32(http.StatusInternalServerError))
if err := svr.consumer.UpdateServiceCallResult(ret); err != nil {
log.Printf("do report service call result : %+v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ratelimit/consumer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.3.2-alpha.2 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/ratelimit/consumer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA=
github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
1 change: 1 addition & 0 deletions examples/ratelimit/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/

package main

Check warning on line 18 in examples/ratelimit/consumer/main.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.19.x)

should have a package comment

Check warning on line 18 in examples/ratelimit/consumer/main.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.15.x)

should have a package comment

import (
"flag"
Expand Down Expand Up @@ -91,6 +91,7 @@
RetStatus: model.RetFail,
},
}
ret.SetRetCode(int32(http.StatusInternalServerError))
ret.SetDelay(delay)
if err := svr.consumer.UpdateServiceCallResult(ret); err != nil {
log.Printf("do report service call result : %+v", err)
Expand Down
2 changes: 1 addition & 1 deletion examples/ratelimit/provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.3.2-alpha.2 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/ratelimit/provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA=
github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
2 changes: 1 addition & 1 deletion examples/route/dynamic/consumer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.3.2-alpha.2 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/route/dynamic/consumer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA=
github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
2 changes: 1 addition & 1 deletion examples/route/dynamic/provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.3.2-alpha.2 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/route/dynamic/provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA=
github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
2 changes: 1 addition & 1 deletion examples/route/nearby/consumer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.3.2-alpha.2 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/route/nearby/consumer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA=
github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
2 changes: 1 addition & 1 deletion examples/route/nearby/provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.4.0 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/route/nearby/provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.4.0 h1:fm7sUtFZC2g9+lLmRCtjGrUow47CY5JDFoZXwwCQGGY=
github.com/polarismesh/specification v1.4.0/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
2 changes: 1 addition & 1 deletion examples/watchinstance/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.3.2-alpha.2 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions examples/watchinstance/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA=
github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down
11 changes: 10 additions & 1 deletion plugin/metrics/common/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ type StatInfoRevisionCollector struct {
currentRevision int64
}

func (src *StatInfoRevisionCollector) IncRevision() int64 {
return atomic.AddInt64(&src.currentRevision, 1)
}

func (src *StatInfoRevisionCollector) GetCurrentRevision() int64 {
return atomic.LoadInt64(&src.currentRevision)
}
Expand Down Expand Up @@ -179,21 +183,26 @@ func PutDataFromContainerInOrder(metricVecCaches map[string]*prometheus.GaugeVec
if !ok {
continue
}
canReport := true
switch rs := metricValue.(type) {
case *StatRevisionMetric:
if rs.GetRevision() < currentRevision-RevisionMaxScope {
// 如果连续两个版本还没有数据,就清除该数据
gauge.Delete(rs.GetLabels())
collector.RemoveStatMetric(rs.GetSignature())
canReport = false
continue
}
if rs.GetRevision() < currentRevision {
// 如果版本为老版本,则清零数据
gauge.Delete(rs.GetLabels())
gauge.With(rs.GetLabels()).Set(0)
canReport = false
continue
}
}
gauge.With(metricValue.GetLabels()).Set(float64(metricValue.GetValue()))
if canReport {
gauge.With(metricValue.GetLabels()).Set(float64(metricValue.GetValue()))
}
}
}
1 change: 0 additions & 1 deletion plugin/metrics/prometheus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (c *Config) SetDefault() {
}
if c.PortStr == "" {
c.port = defaultMetricPort
return
}
if c.Interval == 0 {
c.Interval = 15 * time.Second
Expand Down
21 changes: 14 additions & 7 deletions plugin/metrics/prometheus/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,19 @@ func (pa *PullAction) doAggregation(ctx context.Context) {
action := func() {
defer func() {
if err := recover(); err != nil {
log.GetBaseLogger().Errorf("stat metrics prometheus panic", zap.Any("error", err))
log.GetBaseLogger().Errorf("[metrics][pull] stat metrics prometheus panic", zap.Any("error", err))
}
}()
log.GetBaseLogger().Infof("start aggregation stat metrics prometheus")
log.GetBaseLogger().Infof("[metrics][pull] start aggregation stat metrics prometheus")

statcommon.PutDataFromContainerInOrder(pa.reporter.metricVecCaches, pa.reporter.insCollector,
pa.reporter.insCollector.GetCurrentRevision())
statcommon.PutDataFromContainerInOrder(pa.reporter.metricVecCaches, pa.reporter.circuitBreakerCollector, 0)
statcommon.PutDataFromContainerInOrder(pa.reporter.metricVecCaches, pa.reporter.rateLimitCollector,
pa.reporter.rateLimitCollector.GetCurrentRevision())

log.GetBaseLogger().Debugf("[metrics][push] revision collector inc current revision to %d", pa.reporter.insCollector.IncRevision())
log.GetBaseLogger().Debugf("[metrics][push] collector inc current revision to %d", pa.reporter.rateLimitCollector.IncRevision())
}

for {
Expand All @@ -313,7 +316,7 @@ func (pa *PullAction) Run(ctx context.Context) {
go func() {
ln, err := net.Listen("tcp", fmt.Sprintf("%s:%d", pa.bindIP, pa.bindPort))
if err != nil {
log.GetBaseLogger().Errorf("start metrics http-server fail: %v", err)
log.GetBaseLogger().Errorf("[metrics][push] start metrics http-server fail: %v", err)
pa.bindPort = -1
return
}
Expand All @@ -323,9 +326,9 @@ func (pa *PullAction) Run(ctx context.Context) {
handler: promhttp.HandlerFor(pa.reporter.registry, promhttp.HandlerOpts{}),
}

log.GetBaseLogger().Infof("start metrics http-server address : %s", fmt.Sprintf("%s:%d", pa.bindIP, pa.bindPort))
log.GetBaseLogger().Infof("[metrics][push] start metrics http-server address : %s", fmt.Sprintf("%s:%d", pa.bindIP, pa.bindPort))
if err := http.Serve(ln, &handler); err != nil {
log.GetBaseLogger().Errorf("start metrics http-server fail : %s", err)
log.GetBaseLogger().Errorf("[metrics][push] start metrics http-server fail : %s", err)
return
}
}()
Expand Down Expand Up @@ -365,11 +368,11 @@ func (pa *PushAction) Run(ctx context.Context) {
action := func() {
defer func() {
if err := recover(); err != nil {
log.GetBaseLogger().Errorf("stat metrics prometheus panic", zap.Any("error", err))
log.GetBaseLogger().Errorf("[metrics][push] stat metrics to pushgateway panic", zap.Any("error", err))
}
}()

log.GetBaseLogger().Infof("start push stat metrics prometheus")
log.GetBaseLogger().Infof("[metrics][push] start push stat metrics to pushgateway")

statcommon.PutDataFromContainerInOrder(pa.reporter.metricVecCaches, pa.reporter.insCollector,
pa.reporter.insCollector.GetCurrentRevision())
Expand All @@ -382,7 +385,11 @@ func (pa *PushAction) Run(ctx context.Context) {
Gatherer(pa.reporter.registry).
Push(); err != nil {
log.GetBaseLogger().Errorf("push metrics to pushgateway fail: %s", err.Error())
return
}

log.GetBaseLogger().Debugf("[metrics][push] revision collector inc current revision to %d", pa.reporter.insCollector.IncRevision())
log.GetBaseLogger().Debugf("[metrics][push] collector inc current revision to %d", pa.reporter.rateLimitCollector.IncRevision())
}

for {
Expand Down
Loading