1   /*
2    * Copyright 2025 LY Corporation
3    *
4    * LY Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package com.linecorp.centraldogma.server.internal.replication;
18  
19  import com.google.common.collect.ImmutableList;
20  
21  import com.linecorp.armeria.common.metric.MoreMeters;
22  
23  import io.micrometer.core.instrument.MeterRegistry;
24  import io.micrometer.core.instrument.Tag;
25  import io.micrometer.core.instrument.Timer;
26  
27  final class ReplicationMetrics {
28  
29      private final String projectName;
30      private final Timer executorQueueLatencyTimer;
31      private final Timer lockAcquireSuccessTimer;
32      private final Timer lockAcquireFailureTimer;
33      private final Timer lockReleaseTimer;
34      private final Timer commandExecutionTimer;
35      private final Timer logReplayTimer;
36      private final Timer logStoreTimer;
37  
38      ReplicationMetrics(MeterRegistry registry, String projectName) {
39          this.projectName = projectName;
40          executorQueueLatencyTimer = MoreMeters.newTimer(registry, "replication.executor.queue.latency",
41                                                 ImmutableList.of(Tag.of("project", projectName)));
42          lockAcquireSuccessTimer = MoreMeters.newTimer(registry, "replication.lock.acquisition",
43                                                        ImmutableList.of(Tag.of("project", projectName),
44                                                                         Tag.of("acquired", "true")));
45          lockAcquireFailureTimer = MoreMeters.newTimer(registry, "replication.lock.acquisition",
46                                                        ImmutableList.of(Tag.of("project", projectName),
47                                                                         Tag.of("acquired", "false")));
48          lockReleaseTimer = MoreMeters.newTimer(registry, "replication.lock.release",
49                                                        ImmutableList.of(Tag.of("project", projectName)));
50          commandExecutionTimer = MoreMeters.newTimer(registry, "replication.command.execution",
51                                                      ImmutableList.of(Tag.of("project", projectName)));
52          logReplayTimer = MoreMeters.newTimer(registry, "replication.log.replay",
53                                              ImmutableList.of(Tag.of("project", projectName)));
54          logStoreTimer = MoreMeters.newTimer(registry, "replication.log.store",
55                                              ImmutableList.of(Tag.of("project", projectName)));
56      }
57  
58      Timer executorQueueLatencyTimer() {
59          return executorQueueLatencyTimer;
60      }
61  
62      Timer lockAcquireSuccessTimer() {
63          return lockAcquireSuccessTimer;
64      }
65  
66      Timer lockAcquireFailureTimer() {
67          return lockAcquireFailureTimer;
68      }
69  
70      Timer lockReleaseTimer() {
71          return lockReleaseTimer;
72      }
73  
74      Timer commandExecutionTimer() {
75          return commandExecutionTimer;
76      }
77  
78      Timer logReplayTimer() {
79          return logReplayTimer;
80      }
81  
82      Timer logStoreTimer() {
83          return logStoreTimer;
84      }
85  
86      @Override
87      public boolean equals(Object o) {
88          if (!(o instanceof ReplicationMetrics)) {
89              return false;
90          }
91          final ReplicationMetrics that = (ReplicationMetrics) o;
92          return projectName.equals(that.projectName);
93      }
94  
95      @Override
96      public int hashCode() {
97          return projectName.hashCode();
98      }
99  }