Skip to content

Commit

Permalink
[aggregator] Reduce error handling overhead in rawtcp server
Browse files Browse the repository at this point in the history
  • Loading branch information
vdarulis committed Feb 7, 2021
1 parent f6450c1 commit 0fac338
Showing 1 changed file with 11 additions and 55 deletions.
66 changes: 11 additions & 55 deletions src/aggregator/server/rawtcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,31 @@ func (s *handler) Handle(conn net.Conn) {
case encoding.CounterWithMetadatasType:
untimedMetric = current.CounterWithMetadatas.Counter.ToUnion()
stagedMetadatas = current.CounterWithMetadatas.StagedMetadatas
err = toAddUntimedError(s.aggregator.AddUntimed(untimedMetric, stagedMetadatas))
err = addUntimedError(s.aggregator.AddUntimed(untimedMetric, stagedMetadatas))
case encoding.BatchTimerWithMetadatasType:
untimedMetric = current.BatchTimerWithMetadatas.BatchTimer.ToUnion()
stagedMetadatas = current.BatchTimerWithMetadatas.StagedMetadatas
err = toAddUntimedError(s.aggregator.AddUntimed(untimedMetric, stagedMetadatas))
err = addUntimedError(s.aggregator.AddUntimed(untimedMetric, stagedMetadatas))
case encoding.GaugeWithMetadatasType:
untimedMetric = current.GaugeWithMetadatas.Gauge.ToUnion()
stagedMetadatas = current.GaugeWithMetadatas.StagedMetadatas
err = toAddUntimedError(s.aggregator.AddUntimed(untimedMetric, stagedMetadatas))
err = addUntimedError(s.aggregator.AddUntimed(untimedMetric, stagedMetadatas))
case encoding.ForwardedMetricWithMetadataType:
forwardedMetric = current.ForwardedMetricWithMetadata.ForwardedMetric
forwardMetadata = current.ForwardedMetricWithMetadata.ForwardMetadata
err = toAddForwardedError(s.aggregator.AddForwarded(forwardedMetric, forwardMetadata))
err = addForwardedError(s.aggregator.AddForwarded(forwardedMetric, forwardMetadata))
case encoding.TimedMetricWithMetadataType:
timedMetric = current.TimedMetricWithMetadata.Metric
timedMetadata = current.TimedMetricWithMetadata.TimedMetadata
err = toAddTimedError(s.aggregator.AddTimed(timedMetric, timedMetadata))
err = addTimedError(s.aggregator.AddTimed(timedMetric, timedMetadata))
case encoding.TimedMetricWithMetadatasType:
timedMetric = current.TimedMetricWithMetadatas.Metric
stagedMetadatas = current.TimedMetricWithMetadatas.StagedMetadatas
err = toAddTimedError(s.aggregator.AddTimedWithStagedMetadatas(timedMetric, stagedMetadatas))
err = addTimedError(s.aggregator.AddTimedWithStagedMetadatas(timedMetric, stagedMetadatas))
case encoding.PassthroughMetricWithMetadataType:
passthroughMetric = current.PassthroughMetricWithMetadata.Metric
passthroughMetadata = current.PassthroughMetricWithMetadata.StoragePolicy
err = toAddPassthroughError(s.aggregator.AddPassthrough(passthroughMetric, passthroughMetadata))
err = addPassthroughError(s.aggregator.AddPassthrough(passthroughMetric, passthroughMetadata))
default:
err = newUnknownMessageTypeError(current.Type)
}
Expand Down Expand Up @@ -265,54 +265,10 @@ func (e unknownMessageTypeError) Error() string {
return fmt.Sprintf("unknown message type %v", e.msgType)
}

type addUntimedError struct {
err error
}

func toAddUntimedError(err error) error {
if err == nil {
return nil
}
return addUntimedError{err: err}
}

func (e addUntimedError) Error() string { return e.err.Error() }

type addTimedError struct {
err error
}

func toAddTimedError(err error) error {
if err == nil {
return nil
}
return addTimedError{err: err}
}
type addForwardedError error

func (e addTimedError) Error() string { return e.err.Error() }
type addPassthroughError error

type addForwardedError struct {
err error
}

func toAddForwardedError(err error) error {
if err == nil {
return nil
}
return addForwardedError{err: err}
}

func (e addForwardedError) Error() string { return e.err.Error() }

type addPassthroughError struct {
err error
}

func toAddPassthroughError(err error) error {
if err == nil {
return nil
}
return addPassthroughError{err: err}
}
type addTimedError error

func (e addPassthroughError) Error() string { return e.err.Error() }
type addUntimedError error

0 comments on commit 0fac338

Please sign in to comment.