@@ -159,7 +159,7 @@ const (
159159 journalUpdateTimeout = 2 * time .Second
160160
161161 // healthcheck should query any lightweight metric, this one was chosen randomly
162- healthcheckMetric = "__agg_bucket_receive_delay_sec"
162+ healthcheckMetric = "__agg_bucket_receive_delay_sec" // format.BuiltinMetricMetaAggBucketReceiveDelaySec.Name
163163 healthcheckQuery = `{@name="` + healthcheckMetric + `",@what="avg"}`
164164)
165165
@@ -1172,7 +1172,7 @@ func HandleGetMetric(r *httpRequestHandler) {
11721172}
11731173
11741174func HandleGetPromConfig (h * httpRequestHandler ) {
1175- if ! h .accessInfo .isAdmin () {
1175+ if ! h .accessInfo .bitAdmin {
11761176 err := httpErr (http .StatusNotFound , fmt .Errorf ("config is not found" ))
11771177 respondJSON (h , nil , 0 , 0 , err )
11781178 return
@@ -1186,7 +1186,7 @@ func HandleGetPromConfig(h *httpRequestHandler) {
11861186}
11871187
11881188func HandleGetPromConfigGenerated (h * httpRequestHandler ) {
1189- if ! h .accessInfo .isAdmin () {
1189+ if ! h .accessInfo .bitAdmin {
11901190 err := httpErr (http .StatusNotFound , fmt .Errorf ("config is not found" ))
11911191 respondJSON (h , nil , 0 , 0 , err )
11921192 return
@@ -1288,7 +1288,7 @@ func HandlePostResetFlood(r *httpRequestHandler) {
12881288 if r .checkReadOnlyMode () {
12891289 return
12901290 }
1291- if ! r .accessInfo .isAdmin () {
1291+ if ! r .accessInfo .bitAdmin {
12921292 err := httpErr (http .StatusForbidden , fmt .Errorf ("admin access required" ))
12931293 respondJSON (r , nil , 0 , 0 , err )
12941294 return
@@ -1316,7 +1316,7 @@ func HandlePostPromConfig(r *httpRequestHandler) {
13161316 if r .checkReadOnlyMode () {
13171317 return
13181318 }
1319- if ! r .accessInfo .isAdmin () {
1319+ if ! r .accessInfo .bitAdmin {
13201320 err := httpErr (http .StatusNotFound , fmt .Errorf ("config is not found" ))
13211321 respondJSON (r , nil , 0 , 0 , err )
13221322 return
@@ -1357,7 +1357,7 @@ func HandlePostKnownTags(r *httpRequestHandler) {
13571357 if r .checkReadOnlyMode () {
13581358 return
13591359 }
1360- if ! r .accessInfo .isAdmin () {
1360+ if ! r .accessInfo .bitAdmin {
13611361 err := httpErr (http .StatusNotFound , fmt .Errorf ("not found" ))
13621362 respondJSON (r , nil , 0 , 0 , err )
13631363 return
@@ -1393,7 +1393,7 @@ func HandlePostKnownTags(r *httpRequestHandler) {
13931393}
13941394
13951395func HandleGetKnownTags (h * httpRequestHandler ) {
1396- if ! h .accessInfo .isAdmin () {
1396+ if ! h .accessInfo .bitAdmin {
13971397 err := httpErr (http .StatusNotFound , fmt .Errorf ("config is not found" ))
13981398 respondJSON (h , nil , 0 , 0 , err )
13991399 return
@@ -1621,7 +1621,7 @@ func (h *Handler) handleGetNamespaceList(ai accessInfo, showInvisible bool) (*Ge
16211621}
16221622
16231623func (h * Handler ) handlePostNamespace (ctx context.Context , ai accessInfo , namespace format.NamespaceMeta , create bool ) (* NamespaceInfo , error ) {
1624- if ! ai .isAdmin () {
1624+ if ! ai .bitAdmin {
16251625 return nil , httpErr (http .StatusNotFound , fmt .Errorf ("namespace %s not found" , namespace .Name ))
16261626 }
16271627 if ! create {
@@ -1656,7 +1656,7 @@ func (h *Handler) handlePostNamespace(ctx context.Context, ai accessInfo, namesp
16561656}
16571657
16581658func (h * Handler ) handlePostGroup (ctx context.Context , ai accessInfo , group format.MetricsGroup , create bool ) (* MetricsGroupInfo , error ) {
1659- if ! ai .isAdmin () {
1659+ if ! ai .bitAdmin {
16601660 return nil , httpErr (http .StatusNotFound , fmt .Errorf ("group %s not found" , group .Name ))
16611661 }
16621662 if ! create {
@@ -2177,15 +2177,19 @@ func HandleFrontendStat(r *httpRequestHandler) {
21772177func (h * requestHandler ) queryBadges (ctx context.Context , req seriesRequest , meta * format.MetricMetaValue ) (res seriesResponse , cleanup func ()) {
21782178 timeNow := time .Now ()
21792179 badges := requestHandler {
2180- Handler : h .Handler ,
2181- accessInfo : accessInfo {insecureMode : true },
2180+ Handler : h .Handler ,
2181+ accessInfo : accessInfo {
2182+ user : h .accessInfo .user ,
2183+ service : h .accessInfo .service ,
2184+ bitViewMetric : map [string ]bool {format .BuiltinMetricMetaBadges .Name : true },
2185+ },
21822186 endpointStat : endpointStat {
21832187 timestamp : timeNow ,
21842188 endpoint : h .endpointStat .endpoint ,
21852189 protocol : h .endpointStat .protocol ,
21862190 method : h .endpointStat .method ,
21872191 dataFormat : h .endpointStat .dataFormat ,
2188- metric : "-35" , // format.BuiltinMetricIDBadges
2192+ metric : "-35" , // strconv.Itoa( format.BuiltinMetricIDBadges)
21892193 tokenName : h .endpointStat .tokenName ,
21902194 user : h .endpointStat .user ,
21912195 priority : h .endpointStat .priority ,
@@ -3267,7 +3271,7 @@ func (r *DashboardTimeShifts) UnmarshalJSON(bs []byte) error {
32673271}
32683272
32693273func (r * seriesRequest ) validate (h * requestHandler ) error {
3270- if r .avoidCache && ! h .accessInfo .isAdmin () {
3274+ if r .avoidCache && ! h .accessInfo .bitAdmin {
32713275 return httpErr (404 , fmt .Errorf ("" ))
32723276 }
32733277 if r .step == _1M {
@@ -3322,14 +3326,14 @@ func HandleProfTrace(h *httpRequestHandler) {
33223326}
33233327
33243328func pprofAccessAllowed (h * httpRequestHandler ) bool {
3325- if ok := h .accessInfo .insecureMode || h . accessInfo . bitAdmin ; ! ok {
3329+ if ! h .accessInfo .bitAdmin {
33263330 h .Response ().WriteHeader (http .StatusForbidden )
33273331 return false
33283332 }
33293333 return true
33303334}
33313335
3332- func defaultAccessInfo (h * requestHandler ) (accessInfo , bool ) {
3336+ func healthcheckAccessInfo (h * requestHandler ) (accessInfo , bool ) {
33333337 switch h .endpointStat .endpoint {
33343338 // healthcheck endpoint is used by nginx checks directly without token
33353339 case EndpointHealthcheck :
@@ -3356,7 +3360,7 @@ func (h *requestHandler) init(accessToken, version string) (err error) {
33563360 return fmt .Errorf ("invalid version: %q" , version )
33573361 }
33583362 if h .accessInfo , err = parseAccessToken (h .jwtHelper , accessToken , h .protectedMetricPrefixes , h .LocalMode , h .insecureMode ); err != nil {
3359- if ai , ok := defaultAccessInfo (h ); ! ok {
3363+ if ai , ok := healthcheckAccessInfo (h ); ! ok {
33603364 return err
33613365 } else {
33623366 h .accessInfo = ai
0 commit comments