Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
henryzhx8 committed Oct 31, 2024
1 parent a3f452d commit 83c6524
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions core/pipeline/serializer/SLSSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ bool SLSEventGroupSerializer::Serialize(BatchedEvents&& group, string& res, stri

size_t contentSZ = 0;
contentSZ += GetLogContentSize(METRIC_RESERVED_KEY_NAME.size(), e.GetName().size());
contentSZ += GetLogContentSize(METRIC_RESERVED_KEY_VALUE.size(), metricEventContentCache[i].first.size());
contentSZ
+= GetLogContentSize(METRIC_RESERVED_KEY_VALUE.size(), metricEventContentCache[i].first.size());
contentSZ
+= GetLogContentSize(METRIC_RESERVED_KEY_TIME_NANO.size(), e.GetTimestampNanosecond() ? 19U : 10U);
contentSZ += GetLogContentSize(METRIC_RESERVED_KEY_LABELS.size(), metricEventContentCache[i].second);
Expand Down Expand Up @@ -123,32 +124,38 @@ bool SLSEventGroupSerializer::Serialize(BatchedEvents&& group, string& res, stri

static LogGroupSerializer serializer;
serializer.Prepare(logGroupSZ);
for (size_t i = 0; i < group.mEvents.size(); ++i) {
if (group.mEvents[i].Is<LogEvent>()) {
const auto& logEvent = group.mEvents[i].Cast<LogEvent>();
serializer.StartToAddLog(logSZ[i]);
serializer.AddLogTime(logEvent.GetTimestamp());
for (const auto& kv : logEvent) {
serializer.AddLogContent(kv.first, kv.second);
}
if (enableNs && logEvent.GetTimestampNanosecond()) {
serializer.AddLogTimeNs(logEvent.GetTimestampNanosecond().value());
switch (eventType) {
case PipelineEvent::Type::LOG:
for (size_t i = 0; i < group.mEvents.size(); ++i) {
const auto& logEvent = group.mEvents[i].Cast<LogEvent>();
serializer.StartToAddLog(logSZ[i]);
serializer.AddLogTime(logEvent.GetTimestamp());
for (const auto& kv : logEvent) {
serializer.AddLogContent(kv.first, kv.second);
}
if (enableNs && logEvent.GetTimestampNanosecond()) {
serializer.AddLogTimeNs(logEvent.GetTimestampNanosecond().value());
}
}
} else if (group.mEvents[i].Is<MetricEvent>()) {
const auto& metricEvent = group.mEvents[i].Cast<MetricEvent>();
if (metricEvent.Is<std::monostate>()) {
continue;
break;
case PipelineEvent::Type::METRIC:
for (size_t i = 0; i < group.mEvents.size(); ++i) {
const auto& metricEvent = group.mEvents[i].Cast<MetricEvent>();
if (metricEvent.Is<std::monostate>()) {
continue;
}
serializer.StartToAddLog(logSZ[i]);
serializer.AddLogTime(metricEvent.GetTimestamp());
serializer.AddLogContentMetricLabel(metricEvent, metricEventContentCache[i].second);
serializer.AddLogContentMetricTimeNano(metricEvent);
serializer.AddLogContent(METRIC_RESERVED_KEY_VALUE, metricEventContentCache[i].first);
serializer.AddLogContent(METRIC_RESERVED_KEY_NAME, metricEvent.GetName());
}
serializer.StartToAddLog(logSZ[i]);
serializer.AddLogTime(metricEvent.GetTimestamp());
serializer.AddLogContentMetricLabel(metricEvent, metricEventContentCache[i].second);
serializer.AddLogContentMetricTimeNano(metricEvent);
serializer.AddLogContent(METRIC_RESERVED_KEY_VALUE, metricEventContentCache[i].first);
serializer.AddLogContent(METRIC_RESERVED_KEY_NAME, metricEvent.GetName());
} else {
errorMsg = "unsupported event type in event group";
return false;
}
break;
case PipelineEvent::Type::SPAN:
break;
default:
break;
}
for (const auto& tag : group.mTags.mInner) {
if (tag.first == LOG_RESERVED_KEY_TOPIC) {
Expand Down

0 comments on commit 83c6524

Please sign in to comment.