go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cipd/appengine/impl/monitoring/metrics.go (about) 1 // Copyright 2019 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package monitoring 16 17 import ( 18 "context" 19 20 "go.chromium.org/luci/common/errors" 21 "go.chromium.org/luci/common/tsmon/field" 22 "go.chromium.org/luci/common/tsmon/metric" 23 "go.chromium.org/luci/common/tsmon/types" 24 "go.chromium.org/luci/server/auth" 25 ) 26 27 var bytesRequested = metric.NewCounter( 28 "downloads/bytes", 29 "Bytes requested for download by clients.", 30 &types.MetricMetadata{Units: types.Bytes}, 31 field.String("client_name"), 32 field.String("client_email"), 33 field.String("download_source"), 34 ) 35 36 // FileSize handles file size information. If client requests are being 37 // monitored it will be reported. 38 func FileSize(ctx context.Context, bytes uint64) { 39 cfg, err := monitoringConfig(ctx) 40 if err != nil { 41 errors.Log(ctx, errors.Annotate(err, "failed to fetch monitoring config").Err()) 42 return 43 } 44 if cfg == nil { 45 return 46 } 47 // Technically uint64 -> int64 may overflow but there are bigger problems than 48 // a panic if a user requested a CIPD package larger than math.MaxInt64 bytes. 49 bytesRequested.Add(ctx, int64(bytes), cfg.Label, string(auth.CurrentIdentity(ctx)), "GCS") 50 }