| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package cloudtail | 5 package cloudtail |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/json" | 8 "encoding/json" |
| 9 "fmt" | 9 "fmt" |
| 10 "net/http" | 10 "net/http" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 ResourceID string | 68 ResourceID string |
| 69 | 69 |
| 70 // LogID identifies what sort of log this is. Must be set. | 70 // LogID identifies what sort of log this is. Must be set. |
| 71 LogID string | 71 LogID string |
| 72 | 72 |
| 73 // Debug is true to print log entries to stdout instead of sending them. | 73 // Debug is true to print log entries to stdout instead of sending them. |
| 74 Debug bool | 74 Debug bool |
| 75 } | 75 } |
| 76 | 76 |
| 77 var ( | 77 var ( |
| 78 » entriesCounter = metric.NewCounter("cloudtail/entries", field.String("se
verity")) | 78 » entriesCounter = metric.NewCounter("cloudtail/log_entries", |
| 79 » writesCounter = metric.NewCounter("cloudtail/writes", field.String("res
ult")) | 79 » » field.String("log"), |
| 80 » » field.String("resource_type"), |
| 81 » » field.String("resource_id"), |
| 82 » » field.String("severity")) |
| 83 » writesCounter = metric.NewCounter("cloudtail/api_writes", |
| 84 » » field.String("log"), |
| 85 » » field.String("resource_type"), |
| 86 » » field.String("resource_id"), |
| 87 » » field.String("result")) |
| 80 ) | 88 ) |
| 81 | 89 |
| 82 // NewClient returns new object that knows how to push log entries to a single | 90 // NewClient returns new object that knows how to push log entries to a single |
| 83 // log in Cloud Logging. | 91 // log in Cloud Logging. |
| 84 func NewClient(opts ClientOptions) (Client, error) { | 92 func NewClient(opts ClientOptions) (Client, error) { |
| 85 if opts.Logger == nil { | 93 if opts.Logger == nil { |
| 86 opts.Logger = logging.Null() | 94 opts.Logger = logging.Null() |
| 87 } | 95 } |
| 88 if opts.ProjectID == "" { | 96 if opts.ProjectID == "" { |
| 89 return nil, fmt.Errorf("no ProjectID is provided") | 97 return nil, fmt.Errorf("no ProjectID is provided") |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 170 } |
| 163 if !e.Timestamp.IsZero() { | 171 if !e.Timestamp.IsZero() { |
| 164 metadata.Timestamp = e.Timestamp.UTC().Format(time.RFC33
39Nano) | 172 metadata.Timestamp = e.Timestamp.UTC().Format(time.RFC33
39Nano) |
| 165 } | 173 } |
| 166 req.Entries[i] = &cloudlog.LogEntry{ | 174 req.Entries[i] = &cloudlog.LogEntry{ |
| 167 InsertId: e.InsertID, | 175 InsertId: e.InsertID, |
| 168 Metadata: metadata, | 176 Metadata: metadata, |
| 169 TextPayload: e.TextPayload, | 177 TextPayload: e.TextPayload, |
| 170 StructPayload: e.StructPayload, | 178 StructPayload: e.StructPayload, |
| 171 } | 179 } |
| 172 » » entriesCounter.Add(c.ctx, 1, metadata.Severity) | 180 » » entriesCounter.Add(c.ctx, 1, c.opts.LogID, c.opts.ResourceType,
c.opts.ResourceID, metadata.Severity) |
| 173 } | 181 } |
| 174 if err := c.writeFunc(c.opts.ProjectID, c.opts.LogID, &req); err != nil
{ | 182 if err := c.writeFunc(c.opts.ProjectID, c.opts.LogID, &req); err != nil
{ |
| 175 » » writesCounter.Add(c.ctx, 1, "failure") | 183 » » writesCounter.Add(c.ctx, 1, c.opts.LogID, c.opts.ResourceType, c
.opts.ResourceID, "failure") |
| 176 return err | 184 return err |
| 177 } | 185 } |
| 178 | 186 |
| 179 » writesCounter.Add(c.ctx, 1, "success") | 187 » writesCounter.Add(c.ctx, 1, c.opts.LogID, c.opts.ResourceType, c.opts.Re
sourceID, "success") |
| 180 return nil | 188 return nil |
| 181 } | 189 } |
| OLD | NEW |