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

[receiver/loki] Add logic implementation #19217

Merged
merged 2 commits into from
Apr 5, 2023

Conversation

mar4uk
Copy link
Contributor

@mar4uk mar4uk commented Mar 6, 2023

Description:
The first PR with the skeleton is here #19399
This PR is the second one, with the concrete implementation of the component
Link to tracking Issue:
18635

Testing: Added unit tests

@runforesight
Copy link

runforesight bot commented Mar 6, 2023

Foresight Summary

    
Major Impacts

build-and-test-windows duration(13 seconds) has decreased 31 minutes 27 seconds compared to main branch avg(31 minutes 40 seconds).
View More Details

⭕  build-and-test-windows workflow has finished in 13 seconds (31 minutes 27 seconds less than main branch avg.) and finished at 5th Apr, 2023.


Job Failed Steps Tests
windows-unittest-matrix -     🔗  N/A See Details
windows-unittest -     🔗  N/A See Details

✅  check-links workflow has finished in 48 seconds and finished at 5th Apr, 2023.


Job Failed Steps Tests
changed files -     🔗  N/A See Details
check-links -     🔗  N/A See Details

✅  telemetrygen workflow has finished in 1 minute 7 seconds and finished at 5th Apr, 2023.


Job Failed Steps Tests
build-dev -     🔗  N/A See Details
publish-latest -     🔗  N/A See Details
publish-stable -     🔗  N/A See Details

✅  changelog workflow has finished in 3 minutes 6 seconds (⚠️ 51 seconds more than main branch avg.) and finished at 5th Apr, 2023.


Job Failed Steps Tests
changelog -     🔗  N/A See Details

✅  build-and-test workflow has finished in 42 minutes 43 seconds and finished at 5th Apr, 2023.


Job Failed Steps Tests
unittest-matrix (1.19, connector) -     🔗  ✅ 126  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.20, connector) -     🔗  ✅ 126  ❌ 0  ⏭ 0    🔗 See Details
correctness-metrics -     🔗  ✅ 2  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.20, internal) -     🔗  ✅ 583  ❌ 0  ⏭ 0    🔗 See Details
correctness-traces -     🔗  ✅ 17  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.19, internal) -     🔗  ✅ 583  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.20, extension) -     🔗  ✅ 544  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.19, processor) -     🔗  ✅ 1557  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.19, extension) -     🔗  ✅ 544  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.20, processor) -     🔗  ✅ 1557  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.19, receiver-0) -     🔗  ✅ 2616  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.20, receiver-0) -     🔗  ✅ 2616  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.20, receiver-1) -     🔗  ✅ 1969  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.19, exporter) -     🔗  ✅ 2510  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.20, exporter) -     🔗  ✅ 2510  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.19, receiver-1) -     🔗  ✅ 1969  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.20, other) -     🔗  ✅ 4765  ❌ 0  ⏭ 0    🔗 See Details
integration-tests -     🔗  ✅ 56  ❌ 0  ⏭ 0    🔗 See Details
unittest-matrix (1.19, other) -     🔗  ✅ 4765  ❌ 0  ⏭ 0    🔗 See Details
setup-environment -     🔗  N/A See Details
check-codeowners -     🔗  N/A See Details
build-examples -     🔗  N/A See Details
checks -     🔗  N/A See Details
check-collector-module-version -     🔗  N/A See Details
lint-matrix (receiver-0) -     🔗  N/A See Details
lint-matrix (receiver-1) -     🔗  N/A See Details
lint-matrix (processor) -     🔗  N/A See Details
lint-matrix (extension) -     🔗  N/A See Details
lint-matrix (exporter) -     🔗  N/A See Details
lint-matrix (connector) -     🔗  N/A See Details
lint-matrix (internal) -     🔗  N/A See Details
lint-matrix (other) -     🔗  N/A See Details
lint -     🔗  N/A See Details
unittest (1.20) -     🔗  N/A See Details
unittest (1.19) -     🔗  N/A See Details
cross-compile (darwin, amd64) -     🔗  N/A See Details
cross-compile (darwin, arm64) -     🔗  N/A See Details
cross-compile (linux, 386) -     🔗  N/A See Details
cross-compile (linux, amd64) -     🔗  N/A See Details
cross-compile (linux, arm) -     🔗  N/A See Details
cross-compile (linux, arm64) -     🔗  N/A See Details
cross-compile (linux, ppc64le) -     🔗  N/A See Details
cross-compile (windows, 386) -     🔗  N/A See Details
cross-compile (windows, amd64) -     🔗  N/A See Details
build-package (rpm) -     🔗  N/A See Details
build-package (deb) -     🔗  N/A See Details
windows-msi -     🔗  N/A See Details
publish-check -     🔗  N/A See Details
publish-stable -     🔗  N/A See Details
publish-dev -     🔗  N/A See Details
rotate-milestone -     🔗  N/A See Details

✅  prometheus-compliance-tests workflow has finished in 10 minutes 32 seconds (⚠️ 4 minutes 12 seconds more than main branch avg.) and finished at 5th Apr, 2023.


Job Failed Steps Tests
prometheus-compliance-tests -     🔗  ✅ 21  ❌ 0  ⏭ 0    🔗 See Details

✅  load-tests workflow has finished in 15 minutes 42 seconds (⚠️ 5 minutes 23 seconds more than main branch avg.) and finished at 5th Apr, 2023.


Job Failed Steps Tests
loadtest (TestTraceAttributesProcessor) -     🔗  ✅ 3  ❌ 0  ⏭ 0    🔗 See Details
loadtest (TestIdleMode) -     🔗  ✅ 1  ❌ 0  ⏭ 0    🔗 See Details
loadtest (TestMetric10kDPS|TestMetricsFromFile) -     🔗  ✅ 6  ❌ 0  ⏭ 0    🔗 See Details
loadtest (TestTraceNoBackend10kSPS|TestTrace1kSPSWithAttrs) -     🔗  ✅ 8  ❌ 0  ⏭ 0    🔗 See Details
loadtest (TestMetricResourceProcessor|TestTrace10kSPS) -     🔗  ✅ 12  ❌ 0  ⏭ 0    🔗 See Details
loadtest (TestTraceBallast1kSPSWithAttrs|TestTraceBallast1kSPSAddAttrs) -     🔗  ✅ 10  ❌ 0  ⏭ 0    🔗 See Details
loadtest (TestBallastMemory|TestLog10kDPS) -     🔗  ✅ 18  ❌ 0  ⏭ 0    🔗 See Details
setup-environment -     🔗  N/A See Details

✅  e2e-tests workflow has finished in 17 minutes 47 seconds (⚠️ 3 minutes 42 seconds more than main branch avg.) and finished at 5th Apr, 2023.


Job Failed Steps Tests
kubernetes-test (v1.26.0) -     🔗  N/A See Details
kubernetes-test (v1.25.3) -     🔗  N/A See Details
kubernetes-test (v1.24.7) -     🔗  N/A See Details
kubernetes-test (v1.23.13) -     🔗  N/A See Details

🔎 See details on Foresight

*You can configure Foresight comments in your organization settings page.

@mar4uk mar4uk force-pushed the loki-receiver branch 7 times, most recently from 4c24100 to a8b5649 Compare March 7, 2023 10:55
@mar4uk mar4uk marked this pull request as ready for review March 7, 2023 12:08
@mar4uk mar4uk requested a review from a team March 7, 2023 12:08
@djaglowski djaglowski assigned kovrus and unassigned djaglowski Mar 7, 2023
@mar4uk mar4uk force-pushed the loki-receiver branch 4 times, most recently from db10104 to 0f79045 Compare March 22, 2023 16:35
@mar4uk mar4uk changed the title [WIP] [receiver/loki] New component lokireceiver 2 [receiver/loki] Added logic implementation Mar 22, 2023
@mar4uk
Copy link
Contributor Author

mar4uk commented Mar 23, 2023

@kovrus this PR is ready for review

@jpkrohling jpkrohling changed the title [receiver/loki] Added logic implementation [receiver/loki] Add logic implementation Mar 27, 2023
pkg/translator/loki/loki_to_otlp.go Show resolved Hide resolved
receiver/lokireceiver/internal/util.go Show resolved Hide resolved
receiver/lokireceiver/internal/util.go Show resolved Hide resolved
if len(buffer.Bytes()) > maxSize {
return nil, fmt.Errorf(messageSizeLargerErrFmt, len(buffer.Bytes()), maxSize)
}
switch compression {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the only code path leading here already within a similar switch statement? Perhaps just have the logic from RawSnappy here directly, and perhaps even remove the compression type if snappy is the only supported compression mechanism at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored methods, removed compressionType argument, because currently only Snappy is supported

return r, err
if conf.HTTP != nil {
r.httpMux = http.NewServeMux()
r.httpMux.HandleFunc("/loki/api/v1/push", func(resp http.ResponseWriter, req *http.Request) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing we are missing on the OTLP receiver is the ability to let users specify a path prefix, making it easier to place this code behind a reverse proxy. What do you think about doing the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean we can add prefix as field in the config?

receivers:
  loki:
    protocols:
      http:
    prefix: "/proxy"

and use it in handler:
r.httpMux.HandleFunc(fmt.Sprintf("%s/loki/api/v1/push", r.conf.prefix),...
like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Perhaps "pathPrefix" would be a better name? Or perhaps even something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done afterward. I think we can merge this as is.

}

if r.conf.GRPC != nil {
r.settings.Logger.Info("Creating GRPC server")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a similar entry already in startGRPCServer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this line, thank you!

func (r *lokiReceiver) Push(ctx context.Context, pushRequest *push.PushRequest) (*push.PushResponse, error) {
logs, err := loki.PushRequestToLogs(pushRequest, r.conf.KeepTimestamp)
if err != nil {
r.settings.Logger.Warn(ErrAtLeastOneEntryFailedToProcess, zap.Error(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a bad payload, I think it would be better to perhaps count the number of errors instead of logging a warning on every such error. Perhaps add this to debug level instead, so that people can see what's wrong in non-prod environments, or temporarily?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the number of errors as well.
This error is logged once per push request, which shouldn't be much.
I think it is good to have this warning in production so users can identify what requests contain incorrect labels.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I still think that this has the potential to flood the logs, as a bad payload is typically a sign of a wrongly configured client, I trust your judgment here.

@mar4uk mar4uk force-pushed the loki-receiver branch 3 times, most recently from 7b04776 to b635c45 Compare March 29, 2023 09:59
return r, err
if conf.HTTP != nil {
r.httpMux = http.NewServeMux()
r.httpMux.HandleFunc("/loki/api/v1/push", func(resp http.ResponseWriter, req *http.Request) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done afterward. I think we can merge this as is.

func (r *lokiReceiver) Push(ctx context.Context, pushRequest *push.PushRequest) (*push.PushResponse, error) {
logs, err := loki.PushRequestToLogs(pushRequest, r.conf.KeepTimestamp)
if err != nil {
r.settings.Logger.Warn(ErrAtLeastOneEntryFailedToProcess, zap.Error(err))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I still think that this has the potential to flood the logs, as a bad payload is typically a sign of a wrongly configured client, I trust your judgment here.

@mar4uk
Copy link
Contributor Author

mar4uk commented Apr 5, 2023

@jpkrohling can we merge this? or shall I wait for more approves?

@jpkrohling jpkrohling merged commit 13ce234 into open-telemetry:main Apr 5, 2023
@github-actions github-actions bot added this to the next release milestone Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants