storj/crashcollect/crash/endpoint.go
Qweder93 a5c1e4b4a5 crashcollect: process for receiving panics
Added crashcollect server for tracking panics
on parent process and saving them in file.

Change-Id: I7926f9a16594227a3262e05d216199b7c2857385
2021-04-27 18:57:47 +03:00

49 lines
1.2 KiB
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package crash
import (
"context"
"go.uber.org/zap"
"storj.io/common/identity"
"storj.io/common/rpc/rpcstatus"
"storj.io/storj/private/crashreportpb"
)
// ensures that Endpoint implements crashreportpb.DRPCCrashReportServer.
var _ crashreportpb.DRPCCrashReportServer = (*Endpoint)(nil)
// Endpoint is an drpc controller for receiving crashes.
type Endpoint struct {
crashes *Service
log *zap.Logger
}
// NewEndpoint is a constructor for Endpoint.
func NewEndpoint(log *zap.Logger, crashes *Service) *Endpoint {
return &Endpoint{
crashes: crashes,
log: log,
}
}
// Report is an drpc endpoint for receiving crashes.
func (endpoint *Endpoint) Report(ctx context.Context, r *crashreportpb.ReportRequest) (*crashreportpb.ReportResponse, error) {
peerID, err := identity.PeerIdentityFromContext(ctx)
if err != nil {
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
}
err = endpoint.crashes.Report(peerID.ID, r.GzippedPanic)
if err != nil {
endpoint.log.Error("could not create file with panic", zap.Error(err))
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
}
return &crashreportpb.ReportResponse{}, nil
}