Skip to content

Commit

Permalink
Replace XXXGauges with XXXCounters (yorkie-team#266)
Browse files Browse the repository at this point in the history
We need to check the load on the server for some period. Gauges are used
to track a single value. So, change XXXGauges to XXXCounters.
  • Loading branch information
hackerwins authored Nov 3, 2021
1 parent d03bf60 commit c1b8f31
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion docker/docker-compose-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
grafana:
image: grafana/grafana:5.1.0
image: grafana/grafana:latest
container_name: grafana
ports:
- 3000:3000
Expand Down
2 changes: 1 addition & 1 deletion yorkie/packs/packs.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func pullPack(
return nil, err
}

be.Metrics.SetPushPullSnapshotBytes(len(snapshot))
be.Metrics.AddPushPullSnapshotBytes(len(snapshot))

return change.NewPack(docKey, pulledCP, nil, snapshot), err
}
Expand Down
23 changes: 11 additions & 12 deletions yorkie/profiling/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,21 @@ type Metrics interface {
// ObservePushPullResponseSeconds adds response time metrics for PushPull API.
ObservePushPullResponseSeconds(seconds float64)

// SetPushPullReceivedChanges sets the number of changes metric
// included in the request pack of the PushPull API.
SetPushPullReceivedChanges(count int)
// AddPushPullReceivedChanges sets the number of changes
// included in the request pack of PushPull.
AddPushPullReceivedChanges(count int)

// SetPushPullSentChanges sets the number of changes metric
// included in the response pack of the PushPull API.
SetPushPullSentChanges(count int)
// AddPushPullSentChanges adds the number of changes
// included in the response pack of PushPull.
AddPushPullSentChanges(count int)

// ObservePushPullSnapshotDurationSeconds adds the time
// spent metric when taking snapshots.
// ObservePushPullSnapshotDurationSeconds adds an observation
// for creating snapshot for the response pack.
ObservePushPullSnapshotDurationSeconds(seconds float64)

// SetPushPullSnapshotBytes sets the snapshot byte size.
SetPushPullSnapshotBytes(bytes int)
// AddPushPullSnapshotBytes adds the snapshot byte size of response pack.
AddPushPullSnapshotBytes(bytes int)

// RegisterGRPCServer registers the given gRPC server to collect its
// metrics.
// RegisterGRPCServer registers the given gRPC server.
RegisterGRPCServer(server *grpc.Server)
}
81 changes: 41 additions & 40 deletions yorkie/profiling/prometheus/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type Metrics struct {
agentVersion *prometheus.GaugeVec

pushPullResponseSeconds prometheus.Histogram
pushPullReceivedChanges prometheus.Gauge
pushPullSentChanges prometheus.Gauge
pushPullReceivedChangesTotal prometheus.Counter
pushPullSentChangesTotal prometheus.Counter
pushPullSnapshotDurationSeconds prometheus.Histogram
pushPullSnapshotBytes prometheus.Gauge
pushPullSnapshotBytesTotal prometheus.Counter
}

// NewMetrics creates a new instance of Metrics.
Expand Down Expand Up @@ -70,33 +70,33 @@ func NewMetrics() (*Metrics, error) {
}, []string{"agent_version"}),
pushPullResponseSeconds: promauto.With(reg).NewHistogram(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: "rpcserver",
Name: "pushpull_response_seconds",
Help: "Response time of PushPull API.",
Subsystem: "pushpull",
Name: "response_seconds",
Help: "The response time of PushPull.",
}),
pushPullReceivedChanges: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
pushPullReceivedChangesTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: "rpcserver",
Name: "pushpull_received_changes",
Help: "The number of changes included in a request pack in PushPull API.",
Subsystem: "pushpull",
Name: "received_changes_total",
Help: "The total count of changes included in request packs in PushPull.",
}),
pushPullSentChanges: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
pushPullSentChangesTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: "rpcserver",
Name: "pushpull_sent_changes",
Help: "The number of changes included in a response pack in PushPull API.",
Subsystem: "pushpull",
Name: "sent_changes_total",
Help: "The total count of changes included in response packs in PushPull.",
}),
pushPullSnapshotDurationSeconds: promauto.With(reg).NewHistogram(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: "db",
Name: "pushpull_snapshot_duration_seconds",
Help: "The creation time of snapshot in PushPull API.",
Subsystem: "pushpull",
Name: "snapshot_duration_seconds",
Help: "The creation time of snapshot for response packs in PushPull.",
}),
pushPullSnapshotBytes: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
pushPullSnapshotBytesTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: "db",
Name: "pushpull_snapshot_bytes",
Help: "The number of bytes of Snapshot.",
Subsystem: "pushpull",
Name: "snapshot_bytes_total",
Help: "The total bytes of snapshots for response packs in PushPull.",
}),
}

Expand All @@ -107,40 +107,41 @@ func NewMetrics() (*Metrics, error) {
return metrics, nil
}

// ObservePushPullResponseSeconds adds response time metrics for PushPull API.
// ObservePushPullResponseSeconds adds an observation for response time of
// PushPull.
func (m *Metrics) ObservePushPullResponseSeconds(seconds float64) {
m.pushPullResponseSeconds.Observe(seconds)
}

// SetPushPullReceivedChanges sets the number of changes metric
// included in the request pack of the PushPull API.
func (m *Metrics) SetPushPullReceivedChanges(count int) {
m.pushPullReceivedChanges.Set(float64(count))
// AddPushPullReceivedChanges sets the number of changes
// included in the request pack of PushPull.
func (m *Metrics) AddPushPullReceivedChanges(count int) {
m.pushPullReceivedChangesTotal.Add(float64(count))
}

// SetPushPullSentChanges sets the number of changes metric
// included in the response pack of the PushPull API.
func (m *Metrics) SetPushPullSentChanges(count int) {
m.pushPullSentChanges.Set(float64(count))
// AddPushPullSentChanges adds the number of changes
// included in the response pack of PushPull.
func (m *Metrics) AddPushPullSentChanges(count int) {
m.pushPullSentChangesTotal.Add(float64(count))
}

// ObservePushPullSnapshotDurationSeconds adds the time
// spent metric when taking snapshots.
// ObservePushPullSnapshotDurationSeconds adds an observation
// for creating snapshot for the response pack.
func (m *Metrics) ObservePushPullSnapshotDurationSeconds(seconds float64) {
m.pushPullSnapshotDurationSeconds.Observe(seconds)
}

// SetPushPullSnapshotBytes sets the snapshot byte size.
func (m *Metrics) SetPushPullSnapshotBytes(bytes int) {
m.pushPullSnapshotBytes.Set(float64(bytes))
}

// Registry returns the registry of this metrics.
func (m *Metrics) Registry() *prometheus.Registry {
return m.registry
// AddPushPullSnapshotBytes adds the snapshot byte size of response pack.
func (m *Metrics) AddPushPullSnapshotBytes(bytes int) {
m.pushPullSnapshotBytesTotal.Add(float64(bytes))
}

// RegisterGRPCServer registers the given gRPC server.
func (m *Metrics) RegisterGRPCServer(server *grpc.Server) {
m.serverMetrics.InitializeMetrics(server)
}

// Registry returns the registry of this metrics.
func (m *Metrics) Registry() *prometheus.Registry {
return m.registry
}
4 changes: 2 additions & 2 deletions yorkie/rpc/yorkie_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (s *yorkieServer) PushPull(
}

if pack.HasChanges() {
s.backend.Metrics.SetPushPullReceivedChanges(len(pack.Changes))
s.backend.Metrics.AddPushPullReceivedChanges(len(pack.Changes))

locker, err := s.backend.Coordinator.NewLocker(
ctx,
Expand Down Expand Up @@ -294,7 +294,7 @@ func (s *yorkieServer) PushPull(
return nil, err
}

s.backend.Metrics.SetPushPullSentChanges(len(pbChangePack.Changes))
s.backend.Metrics.AddPushPullSentChanges(len(pbChangePack.Changes))
s.backend.Metrics.ObservePushPullResponseSeconds(gotime.Since(start).Seconds())

return &api.PushPullResponse{
Expand Down

0 comments on commit c1b8f31

Please sign in to comment.