Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: third_party/grpc/test/cpp/util/metrics_server.h

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *is % allowed in string
32 */
33 #ifndef GRPC_TEST_CPP_METRICS_SERVER_H
34 #define GRPC_TEST_CPP_METRICS_SERVER_H
35
36 #include <map>
37 #include <mutex>
38
39 #include "src/proto/grpc/testing/metrics.grpc.pb.h"
40 #include "src/proto/grpc/testing/metrics.pb.h"
41
42 /*
43 * This implements a Metrics server defined in
44 * src/proto/grpc/testing/metrics.proto. Any
45 * test service can use this to export Metrics (TODO (sreek): Only Gauges for
46 * now).
47 *
48 * Example:
49 * MetricsServiceImpl metricsImpl;
50 * ..
51 * // Create Gauge(s). Note: Gauges can be created even after calling
52 * // 'StartServer'.
53 * Gauge gauge1 = metricsImpl.CreateGauge("foo",is_present);
54 * // gauge1 can now be used anywhere in the program to set values.
55 * ...
56 * // Create the metrics server
57 * std::unique_ptr<grpc::Server> server = metricsImpl.StartServer(port);
58 * server->Wait(); // Note: This is blocking.
59 */
60 namespace grpc {
61 namespace testing {
62
63 // TODO(sreek): Add support for other types of Gauges like Double, String in
64 // future
65 class Gauge {
66 public:
67 Gauge(long initial_val);
68 void Set(long new_val);
69 long Get();
70
71 private:
72 long val_;
73 std::mutex val_mu_;
74 };
75
76 class MetricsServiceImpl GRPC_FINAL : public MetricsService::Service {
77 public:
78 grpc::Status GetAllGauges(ServerContext* context, const EmptyMessage* request,
79 ServerWriter<GaugeResponse>* writer) GRPC_OVERRIDE;
80
81 grpc::Status GetGauge(ServerContext* context, const GaugeRequest* request,
82 GaugeResponse* response) GRPC_OVERRIDE;
83
84 // Create a Gauge with name 'name'. is_present is set to true if the Gauge
85 // is already present in the map.
86 // NOTE: CreateGauge can be called anytime (i.e before or after calling
87 // StartServer).
88 std::shared_ptr<Gauge> CreateGauge(const grpc::string& name,
89 bool* already_present);
90
91 std::unique_ptr<grpc::Server> StartServer(int port);
92
93 private:
94 std::map<string, std::shared_ptr<Gauge>> gauges_;
95 std::mutex mu_;
96 };
97
98 } // namespace testing
99 } // namespace grpc
100
101 #endif // GRPC_TEST_CPP_METRICS_SERVER_H
OLDNEW
« no previous file with comments | « third_party/grpc/test/cpp/util/grpc_cli.cc ('k') | third_party/grpc/test/cpp/util/metrics_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698