Skip to content

Commit

Permalink
Set timestamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Aug 26, 2024
1 parent 14976a0 commit 87fddec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions auditing/auditing-interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"log/slog"
"net/http"
"time"

"connectrpc.com/connect"
"github.com/emicklei/go-restful/v3"
Expand Down Expand Up @@ -45,6 +46,7 @@ func UnaryServerInterceptor(a Auditing, logger *slog.Logger, shouldAudit func(fu
childCtx := context.WithValue(ctx, rest.RequestIDKey, requestID)

auditReqContext := Entry{
Timestamp: time.Now(),
RequestId: requestID,
Type: EntryTypeGRPC,
Detail: EntryDetailGRPCUnary,
Expand Down Expand Up @@ -106,6 +108,7 @@ func StreamServerInterceptor(a Auditing, logger *slog.Logger, shouldAudit func(f
}

auditReqContext := Entry{
Timestamp: time.Now(),
RequestId: requestID,
Detail: EntryDetailGRPCStream,
Path: info.FullMethod,
Expand Down Expand Up @@ -166,6 +169,7 @@ func (a auditingConnectInterceptor) WrapStreamingClient(next connect.StreamingCl
childCtx := context.WithValue(ctx, rest.RequestIDKey, requestID)

auditReqContext := Entry{
Timestamp: time.Now(),
RequestId: requestID,
Detail: EntryDetailGRPCStream,
Path: s.Procedure,
Expand Down Expand Up @@ -215,6 +219,7 @@ func (a auditingConnectInterceptor) WrapStreamingHandler(next connect.StreamingH
childCtx := context.WithValue(ctx, rest.RequestIDKey, requestID)

auditReqContext := Entry{
Timestamp: time.Now(),
RequestId: requestID,
Detail: EntryDetailGRPCStream,
Path: shc.Spec().Procedure,
Expand Down Expand Up @@ -278,6 +283,7 @@ func (i auditingConnectInterceptor) WrapUnary(next connect.UnaryFunc) connect.Un
childCtx := context.WithValue(ctx, rest.RequestIDKey, requestID)

auditReqContext := Entry{
Timestamp: time.Now(),
RequestId: requestID,
Detail: EntryDetailGRPCUnary,
Path: ar.Spec().Procedure,
Expand Down Expand Up @@ -381,6 +387,7 @@ func HttpFilter(a Auditing, logger *slog.Logger) (restful.FilterFunction, error)
requestID = uuid.NewString()
}
auditReqContext := Entry{
Timestamp: time.Now(),
RequestId: requestID,
Type: EntryTypeHTTP,
Detail: EntryDetail(r.Method),
Expand Down
5 changes: 5 additions & 0 deletions auditing/timescaledb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"encoding/json"
"errors"
"fmt"
"log/slog"
"reflect"
Expand Down Expand Up @@ -191,6 +192,10 @@ func (a *timescaleAuditing) Flush() error {
}

func (a *timescaleAuditing) Index(entry Entry) error {
if entry.Timestamp.IsZero() {
return errors.New("timestamp is not set")
}

q, _, err := sq.
Insert("traces").
Columns("timestamp", "entry").
Expand Down

0 comments on commit 87fddec

Please sign in to comment.