Add 'app' and 'data' fields to report API (#6)
This commit is contained in:
parent
3568dc9efa
commit
112158fd47
2 changed files with 25 additions and 9 deletions
|
@ -40,6 +40,8 @@ The body of the request should be a JSON object with the following fields:
|
|||
|
||||
* `user_agent`: Application user-agent. Included in the `details.log.gz` file.
|
||||
|
||||
* `app`: Identifier for the application (eg 'riot-web').
|
||||
|
||||
* `version`: Application version. Included in the `details.log.gz` file.
|
||||
|
||||
* `logs`: an of log files. Each entry in the list should be an object with the
|
||||
|
@ -47,4 +49,8 @@ The body of the request should be a JSON object with the following fields:
|
|||
|
||||
* `id`: textual identifier for the logs. Currently ignored.
|
||||
* `lines`: log data. Lines should be separated by newline characters (encoded
|
||||
as `\n`, as normal in JSON).
|
||||
as `\n`, as normal in JSON).
|
||||
|
||||
* `data`: a set of arbitrary name/value strings to include in the
|
||||
`details.log.gz` file. (Note that the values must be strings; numbers,
|
||||
objects and arrays will be rejected).
|
||||
|
|
|
@ -41,10 +41,12 @@ type submitServer struct {
|
|||
}
|
||||
|
||||
type payload struct {
|
||||
Text string `json:"text"`
|
||||
Version string `json:"version"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
Logs []logEntry `json:"logs"`
|
||||
Text string `json:"text"`
|
||||
AppName string `json:"app"`
|
||||
Version string `json:"version"`
|
||||
UserAgent string `json:"user_agent"`
|
||||
Logs []logEntry `json:"logs"`
|
||||
Data map[string]string `json:"data"`
|
||||
}
|
||||
|
||||
type logEntry struct {
|
||||
|
@ -72,7 +74,7 @@ func (s *submitServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
var p payload
|
||||
if err := json.NewDecoder(req.Body).Decode(&p); err != nil {
|
||||
respond(400, w)
|
||||
http.Error(w, fmt.Sprintf("Could not decode payload: %s", err.Error()), 400)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -93,12 +95,20 @@ func (s *submitServer) saveReport(ctx context.Context, p payload) error {
|
|||
// "bugreport-20170115-112233-N.log.gz" => oldest log
|
||||
t := time.Now().UTC()
|
||||
prefix := t.Format("2006-01-02/150405")
|
||||
summary := fmt.Sprintf(
|
||||
"%s\n\nNumber of logs: %d\nVersion: %s\nUser-Agent: %s\n", p.Text, len(p.Logs), p.Version, p.UserAgent,
|
||||
|
||||
var summaryBuf bytes.Buffer
|
||||
fmt.Fprintf(
|
||||
&summaryBuf,
|
||||
"%s\n\nNumber of logs: %d\nApplication: %s\nVersion: %s\nUser-Agent: %s\n",
|
||||
p.Text, len(p.Logs), p.AppName, p.Version, p.UserAgent,
|
||||
)
|
||||
if err := gzipAndSave([]byte(summary), prefix, "details.log.gz"); err != nil {
|
||||
for k, v := range p.Data {
|
||||
fmt.Fprintf(&summaryBuf, "%s: %s\n", k, v)
|
||||
}
|
||||
if err := gzipAndSave(summaryBuf.Bytes(), prefix, "details.log.gz"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i, log := range p.Logs {
|
||||
if err := gzipAndSave([]byte(log.Lines), prefix, fmt.Sprintf("logs-%d.log.gz", i)); err != nil {
|
||||
return err // TODO: Rollback?
|
||||
|
|
Reference in a new issue