Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aggregator] Reduce error handling overhead in rawtcp server #3183

Merged
merged 1 commit into from
Feb 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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