4
4
#include < library/cpp/monlib/service/pages/templates.h>
5
5
#include < library/cpp/string_utils/quote/quote.h>
6
6
7
+ #include < util/string/builder.h>
7
8
#include < util/string/split.h>
8
9
#include < util/system/tls.h>
9
10
@@ -26,6 +27,19 @@ TMaybe<EFormat> ParseFormat(TStringBuf str) {
26
27
}
27
28
}
28
29
30
+ namespace {
31
+
32
+ TStringBuf GetParams (NMonitoring::IMonHttpRequest& request) {
33
+ TStringBuf uri = request.GetUri ();
34
+ TStringBuf params = uri.After (' ?' );
35
+ if (params.Size () == uri.Size ()) {
36
+ params.Clear ();
37
+ }
38
+ return params;
39
+ }
40
+
41
+ }
42
+
29
43
void TDynamicCountersPage::Output (NMonitoring::IMonHttpRequest& request) {
30
44
if (OutputCallback) {
31
45
OutputCallback ();
@@ -37,28 +51,51 @@ void TDynamicCountersPage::Output(NMonitoring::IMonHttpRequest& request) {
37
51
};
38
52
39
53
TVector<TStringBuf> parts;
40
- StringSplitter (request.GetPathInfo ())
41
- .Split (' /' )
42
- .SkipEmpty ()
43
- .Collect (&parts);
44
-
45
- TMaybe<EFormat> format = !parts.empty () ? ParseFormat (parts.back ()) : Nothing ();
46
- if (format) {
47
- parts.pop_back ();
48
- }
54
+ TMaybe<EFormat> format;
55
+ TStringBuf params = GetParams (request);
56
+
57
+ if (request.GetPathInfo ().empty () && !params.empty ()) {
58
+ StringSplitter (params).Split (' &' ).SkipEmpty ().Consume ([&](TStringBuf part) {
59
+ TStringBuf name;
60
+ TStringBuf value;
61
+ part.Split (' =' , name, value);
62
+ if (name.StartsWith (" @" )) {
63
+ if (name == " @format" ) {
64
+ format = ParseFormat (value);
65
+ } else if (name == " @name_label" ) {
66
+ nameLabel = value;
67
+ } else if (name == " @private" ) {
68
+ visibility = TCountableBase::EVisibility::Private;
69
+ }
70
+ } else {
71
+ parts.push_back (part);
72
+ }
73
+ return true ;
74
+ });
75
+ } else {
76
+ StringSplitter (request.GetPathInfo ())
77
+ .Split (' /' )
78
+ .SkipEmpty ()
79
+ .Collect (&parts);
80
+
81
+ format = !parts.empty () ? ParseFormat (parts.back ()) : Nothing ();
82
+ if (format) {
83
+ parts.pop_back ();
84
+ }
49
85
50
- if (!parts.empty () && parts.back ().StartsWith (TStringBuf (" name_label=" ))) {
51
- TVector<TString> labels;
52
- StringSplitter (parts.back ()).Split (' =' ).SkipEmpty ().Collect (&labels);
53
- if (labels.size () == 2U ) {
54
- nameLabel = labels.back ();
86
+ if (!parts.empty () && parts.back ().StartsWith (TStringBuf (" name_label=" ))) {
87
+ TVector<TString> labels;
88
+ StringSplitter (parts.back ()).Split (' =' ).SkipEmpty ().Collect (&labels);
89
+ if (labels.size () == 2U ) {
90
+ nameLabel = labels.back ();
91
+ }
92
+ parts.pop_back ();
55
93
}
56
- parts.pop_back ();
57
- }
58
94
59
- if (!parts.empty () && parts.back () == TStringBuf (" private" )) {
60
- visibility = TCountableBase::EVisibility::Private;
61
- parts.pop_back ();
95
+ if (!parts.empty () && parts.back () == TStringBuf (" private" )) {
96
+ visibility = TCountableBase::EVisibility::Private;
97
+ parts.pop_back ();
98
+ }
62
99
}
63
100
64
101
auto counters = Counters;
@@ -121,9 +158,15 @@ void TDynamicCountersPage::HandleAbsentSubgroup(IMonHttpRequest& request) {
121
158
122
159
void TDynamicCountersPage::BeforePre (IMonHttpRequest& request) {
123
160
IOutputStream& out = request.Output ();
161
+ TStringBuf params = GetParams (request);
162
+ TStringBuilder base;
163
+ base << Path << ' ?' ;
164
+ if (!params.empty ()) {
165
+ base << params << ' &' ;
166
+ }
124
167
HTML (out) {
125
168
DIV () {
126
- out << " <a href='" << request. GetPath () << " / json'>Counters as JSON</a>" ;
169
+ out << " <a href='" << base << " @format= json'>Counters as JSON</a>" ;
127
170
out << " for Solomon" ;
128
171
}
129
172
@@ -133,9 +176,11 @@ void TDynamicCountersPage::BeforePre(IMonHttpRequest& request) {
133
176
UL () {
134
177
currentCounters->EnumerateSubgroups ([&](const TString& name, const TString& value) {
135
178
LI () {
136
- TString pathPart = name + " =" + value;
137
- Quote (pathPart, " " );
138
- out << " \n <a href='" << request.GetPath () << " /" << pathPart << " '>" << name << " " << value << " </a>" ;
179
+ auto escName = name;
180
+ auto escValue = value;
181
+ Quote (escName);
182
+ Quote (escValue);
183
+ out << " \n <a href='" << base << escName << ' =' << escValue << " '>" << name << " " << value << " </a>" ;
139
184
}
140
185
});
141
186
}
0 commit comments