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

Fix return values of Matrix and Vector during query range in QueryShardingMiddleware #4457

Merged
merged 2 commits into from
Oct 12, 2021

Conversation

kavirajk
Copy link
Collaborator

@kavirajk kavirajk commented Oct 11, 2021

What this PR does / why we need it:
During querysharding, when result type is either Matrix or Vector and when the results are empty, instead of returning empty responses, it return nil which breaks the final JSON encoding.

Which issue(s) this PR fixes:
Fixes: #4420

Special notes for your reviewer:
NA

Checklist

  • Documentation added
  • Tests updated

@cyriltovena
Copy link
Contributor

Nice let's verify with a test

@kavirajk
Copy link
Collaborator Author

Tried writing quick test yesterda, but realized its bit tricky. As these handlers are setup inside initQueryWorker(which needs lots of dependency) plus these handlers are available inside Process (interface) under service.Service (again an interface).

I will split setting up this handlers to separate function. So easy to test only the middleware chaining.

Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
Signed-off-by: Kaviraj <kavirajkanagaraj@gmail.com>
@kavirajk kavirajk changed the title Fix middleware order for correct JSON marshaling Fix return values of Matrix and Vector during query range Oct 12, 2021
@kavirajk kavirajk changed the title Fix return values of Matrix and Vector during query range Fix return values of Matrix and Vector during query range in QueryShardingMiddleware Oct 12, 2021
@kavirajk kavirajk marked this pull request as ready for review October 12, 2021 10:50
@kavirajk kavirajk requested a review from a team as a code owner October 12, 2021 10:50
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena
Copy link
Contributor

Can you test after and before in dev please too ?

@kavirajk
Copy link
Collaborator Author

http "http://localhost:3100/loki/api/v1/query_range?query=count_over_time({foo=%22bar%22}[1m])"

Before fix

{
    "data": {
        "result": null,
        "resultType": "matrix",
        "stats": {
            "ingester": {
                "compressedBytes": 0,
                "decompressedBytes": 0,
                "decompressedLines": 0,
                "headChunkBytes": 0,
                "headChunkLines": 0,
                "totalBatches": 0,
                "totalChunksMatched": 0,
                "totalDuplicates": 0,
                "totalLinesSent": 0,
                "totalReached": 1
            },
            "store": {
                "chunksDownloadTime": 0,
                "compressedBytes": 0,
                "decompressedBytes": 0,
                "decompressedLines": 0,
                "headChunkBytes": 0,
                "headChunkLines": 0,
                "totalChunksDownloaded": 0,
                "totalChunksRef": 0,
                "totalDuplicates": 0
            },
            "summary": {
                "bytesProcessedPerSecond": 0,
                "execTime": 0.002188372,
                "linesProcessedPerSecond": 0,
                "totalBytesProcessed": 0,
                "totalLinesProcessed": 0
            }
        }
    },
    "status": "success"
}

After fix

{
    "data": {
        "result": [],
        "resultType": "matrix",
        "stats": {
            "ingester": {
                "compressedBytes": 0,
                "decompressedBytes": 0,
                "decompressedLines": 0,
                "headChunkBytes": 0,
                "headChunkLines": 0,
                "totalBatches": 0,
                "totalChunksMatched": 0,
                "totalDuplicates": 0,
                "totalLinesSent": 0,
                "totalReached": 28
            },
            "store": {
                "chunksDownloadTime": 0,
                "compressedBytes": 0,
                "decompressedBytes": 0,
                "decompressedLines": 0,
                "headChunkBytes": 0,
                "headChunkLines": 0,
                "totalChunksDownloaded": 0,
                "totalChunksRef": 0,
                "totalDuplicates": 0
            },
            "summary": {
                "bytesProcessedPerSecond": 0,
                "execTime": 0.005709232,
                "linesProcessedPerSecond": 0,
                "totalBytesProcessed": 0,
                "totalLinesProcessed": 0
            }
        }
    },
    "status": "success"
}

NOTE: response result key
Looks like it happens only on single-binary mode.

@cyriltovena
Copy link
Contributor

Nice work kavi ❤️

@cyriltovena cyriltovena merged commit 2e1279d into main Oct 12, 2021
@cyriltovena cyriltovena deleted the fix-query-result-null branch October 12, 2021 14:50
@cyriltovena
Copy link
Contributor

Can you sync back on the issue to make sure it was runing on single binary just to make sure we didn;'t miss anything please.

@BitProcessor
Copy link

BitProcessor commented Oct 12, 2021

Can you sync back on the issue to make sure it was runing on single binary just to make sure we didn;'t miss anything please.

@cyriltovena
I am the author of #4420 and encountered the issue in distributed mode.

Retested today, with Grafana 8.2.1 and Loki in distributed mode, using image docker.io/grafana/loki:2.3.0 for the various components.
Source:

  chart:
    repository: https://grafana.github.io/helm-charts
    name: loki-distributed
    version: 0.38.0

Error in distributed mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loki count_over_time null handling goes wrong
4 participants