Commit 89e46b0b authored by Nick Thomas's avatar Nick Thomas

Merge branch 'jv-log-lsif-zip-cache' into 'master'

Add logging for local LSIF ZIP caching

See merge request gitlab-org/gitlab-workhorse!579
parents df805fb1 1001b660
---
title: Add logging for local LSIF ZIP caching
merge_request: 579
author:
type: added
...@@ -2,11 +2,14 @@ package parser ...@@ -2,11 +2,14 @@ package parser
import ( import (
"archive/zip" "archive/zip"
"context"
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"gitlab.com/gitlab-org/labkit/log"
) )
var ( var (
...@@ -23,7 +26,7 @@ type Config struct { ...@@ -23,7 +26,7 @@ type Config struct {
TempPath string TempPath string
} }
func NewParser(r io.Reader, config Config) (io.ReadCloser, error) { func NewParser(ctx context.Context, r io.Reader, config Config) (io.ReadCloser, error) {
docs, err := NewDocs(config) docs, err := NewDocs(config)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -45,6 +48,7 @@ func NewParser(r io.Reader, config Config) (io.ReadCloser, error) { ...@@ -45,6 +48,7 @@ func NewParser(r io.Reader, config Config) (io.ReadCloser, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.WithContextFields(ctx, log.Fields{"lsif_zip_cache_bytes": size}).Print("cached incoming LSIF zip on disk")
zr, err := zip.NewReader(tempFile, size) zr, err := zip.NewReader(tempFile, size)
if err != nil { if err != nil {
......
...@@ -3,6 +3,7 @@ package parser ...@@ -3,6 +3,7 @@ package parser
import ( import (
"archive/zip" "archive/zip"
"bytes" "bytes"
"context"
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil" "io/ioutil"
...@@ -42,7 +43,7 @@ func createFiles(t *testing.T, filePath, tmpDir string) { ...@@ -42,7 +43,7 @@ func createFiles(t *testing.T, filePath, tmpDir string) {
file, err := os.Open(filePath) file, err := os.Open(filePath)
require.NoError(t, err) require.NoError(t, err)
parser, err := NewParser(file, Config{}) parser, err := NewParser(context.Background(), file, Config{})
require.NoError(t, err) require.NoError(t, err)
zipFileName := tmpDir + ".zip" zipFileName := tmpDir + ".zip"
......
package parser package parser
import ( import (
"context"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
...@@ -21,7 +22,7 @@ func BenchmarkGenerate(b *testing.B) { ...@@ -21,7 +22,7 @@ func BenchmarkGenerate(b *testing.B) {
file, err := os.Open(filePath) file, err := os.Open(filePath)
require.NoError(b, err) require.NoError(b, err)
parser, err := NewParser(file, Config{}) parser, err := NewParser(context.Background(), file, Config{})
require.NoError(b, err) require.NoError(b, err)
_, err = io.Copy(ioutil.Discard, parser) _, err = io.Copy(ioutil.Discard, parser)
......
...@@ -187,7 +187,7 @@ func handleLsifUpload(ctx context.Context, reader io.Reader, tempPath, filename ...@@ -187,7 +187,7 @@ func handleLsifUpload(ctx context.Context, reader io.Reader, tempPath, filename
TempPath: tempPath, TempPath: tempPath,
} }
return parser.NewParser(reader, parserConfig) return parser.NewParser(ctx, reader, parserConfig)
} }
func (rew *rewriter) copyPart(ctx context.Context, name string, p *multipart.Part) error { func (rew *rewriter) copyPart(ctx context.Context, name string, p *multipart.Part) error {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment