Skip to content

Commit

Permalink
Merge branch 'main' into log-4544
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoBraveCoding committed Dec 18, 2023
2 parents 155b976 + 724a841 commit ba306cf
Show file tree
Hide file tree
Showing 60 changed files with 1,608 additions and 492 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/snyk-pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ jobs:
continue-on-error: true
id: should-comment
run: |
if [[ $(wc -l < snyk.txt) -gt 1 ]]; then exit 0; fi
if [[ $(wc -l < snyk.txt) -gt 1 ]]; then
echo "\nTo see more details on these vulnerabilities, and how/where to fix them, please run `make scan-vulnerabilities` on your branch. If these were not introduced by your PR, please considering fixing them in `main` via a subsequent PR. Thanks!" >> snyk.txt
exit 0;
fi
exit 1
- name: Comment on PR with Snyk scan results
Expand Down
23 changes: 19 additions & 4 deletions .github/workflows/trivy-pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ jobs:
make loki-image
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
- name: Run Trivy vulnerability scanner
- name: Run Trivy image scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "docker.io/grafana/loki:${{ env.IMAGE_TAG }}"
format: "json"
output: "trivy.json"
output: "trivy-image.json"
severity: "CRITICAL,HIGH"

- name: Run Trivy fs scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: "fs"
scan-ref: "go.mod"
format: "json"
output: "trivy-fs.json"
severity: "CRITICAL,HIGH"

- name: Prepare Trivy Message
Expand All @@ -35,13 +44,19 @@ jobs:
uses: sergeysova/jq-action@v2
continue-on-error: true
with:
cmd: jq -r '.Results[] | select(.Vulnerabilities != null) | .Vulnerabilities[] | "* **\(.Severity)** [\(.Title)](\(.PrimaryURL)) in `\(.PkgName)` v\(.InstalledVersion). Fixed in v\(.FixedVersion)"' trivy.json >> trivy.txt
cmd: |
jq -r '.Results[] | select(.Vulnerabilities != null) | .Target as $target | .Type as $type | .Vulnerabilities[] | "* **\(.Severity)**, Target: \($target), Type: \($type) [\(.Title)](\(.PrimaryURL)) in `\(.PkgName)` v\(.InstalledVersion). Fixed in v\(.FixedVersion)"' trivy-image.json >> trivy.txt
jq -r '.Results[] | select(.Vulnerabilities != null) | .Target as $target | .Type as $type | .Vulnerabilities[] | "* **\(.Severity)**, Target: \($target), Type: \($type) [\(.Title)](\(.PrimaryURL)) in `\(.PkgName)` v\(.InstalledVersion). Fixed in v\(.FixedVersion)"' trivy-fs.json >> trivy.text
- name: Determine whether to comment
continue-on-error: true
id: should-comment
run: |
if [[ $(wc -l < trivy.txt) -gt 1 ]]; then exit 0; fi
if [[ $(wc -l < trivy.txt) -gt 1 ]]; then
echo "\nTo see more details on these vulnerabilities, and how/where to fix them, please run `make scan-vulnerabilities` on your branch. If these were not introduced by your PR, please considering fixing them in `main` via a subsequent PR. Thanks!" >> trivy.txt
exit 0;
fi
exit 1
- name: Comment on PR with Trivy scan results
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

##### Enhancements

* [11363](https://github.com/grafana/loki/pull/11477) **MichelHollands**: support GET for /ingester/shutdown
* [11363](https://github.com/grafana/loki/pull/11363) **kavirajk**: bugfix(memcached): Make memcached batch fetch truely context aware.
* [11319](https://github.com/grafana/loki/pull/11319) **someStrangerFromTheAbyss**: Helm: Add extraContainers to the write pods.
* [11243](https://github.com/grafana/loki/pull/11243) **kavirajk**: Inflight-logging: Add extra metadata to inflight requests logging.
Expand Down Expand Up @@ -48,11 +49,13 @@

##### Changes

* [11490](https://github.com/grafana/loki/pull/11490) **andresperezl**: Helm: Use `/ingester/shutdown` for `preStop` hook in write pods.
* [10366](https://github.com/grafana/loki/pull/10366) **shantanualsi** Upgrade thanos objstore, dskit and other modules
* [10451](https://github.com/grafana/loki/pull/10451) **shantanualsi** Upgrade thanos `objstore`
* [10814](https://github.com/grafana/loki/pull/10814) **shantanualsi,kaviraj** Upgrade prometheus to v0.47.1 and dskit
* [10959](https://github.com/grafana/loki/pull/10959) **slim-bean** introduce a backoff wait on subquery retries.
* [11121](https://github.com/grafana/loki/pull/11121) **periklis** Ensure all lifecycler cfgs ref a valid IPv6 addr and port combination
* [10650](https://github.com/grafana/loki/pull/10650) **matthewpi** Ensure the frontend uses a valid IPv6 addr and port combination

#### Promtail

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ dev-k3d-down:
.PHONY: trivy
trivy: loki-image
trivy i $(IMAGE_PREFIX)/loki:$(IMAGE_TAG)
trivy fs go.mod

# Synk is also used to scan for vulnerabilities, and detects things that trivy might miss
.PHONY: snyk
Expand Down
7 changes: 3 additions & 4 deletions clients/pkg/promtail/discovery/consulagent/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package consulagent
import (
"context"
"encoding/json"
"fmt"
"net"
"net/http"
"strconv"
Expand Down Expand Up @@ -527,9 +526,9 @@ func (srv *consulService) watch(ctx context.Context, ch chan<- []*targetgroup.Gr
// since the service may be registered remotely through a different node.
var addr string
if srvCheck.Service.Address != "" {
addr = net.JoinHostPort(srvCheck.Service.Address, fmt.Sprintf("%d", srvCheck.Service.Port))
addr = net.JoinHostPort(srvCheck.Service.Address, strconv.Itoa(srvCheck.Service.Port))
} else {
addr = net.JoinHostPort(member.Addr, fmt.Sprintf("%d", srvCheck.Service.Port))
addr = net.JoinHostPort(member.Addr, strconv.Itoa(srvCheck.Service.Port))
}

labels := model.LabelSet{
Expand Down Expand Up @@ -560,7 +559,7 @@ func (srv *consulService) watch(ctx context.Context, ch chan<- []*targetgroup.Gr
// Add all key/value pairs from the service's tagged addresses as their own labels.
for k, v := range srvCheck.Service.TaggedAddresses {
name := strutil.SanitizeLabelName(k)
address := fmt.Sprintf("%s:%d", v.Address, v.Port)
address := net.JoinHostPort(v.Address, strconv.Itoa(v.Port))
labels[taggedAddressesLabel+model.LabelName(name)] = model.LabelValue(address)
}

Expand Down
4 changes: 2 additions & 2 deletions docs/sources/get-started/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The Docker Compose configuration instantiates the following components, each in
- **Minio** an S3-compatible object store which Loki uses to store its index and chunks.
- **Grafana** which provides visualization of the log lines captured within Loki.

![Getting started sample application](get-started-flog.png)
{{< figure max-width="75%" src="/media/docs/loki/get-started-flog.png" caption="Getting started sample application" alt="Getting started sample application">}}

## Installing Loki and collecting sample logs

Expand Down Expand Up @@ -80,7 +80,7 @@ Once you have collected logs, you will want to view them. You can view your log

The test environment includes [Grafana](https://grafana.com/docs/grafana/latest/), which you can use to query and observe the sample logs generated by the flog application. You can access the Grafana cluster by navigating to [http://localhost:3000](http://localhost:3000). The Grafana instance provided with this demo has a Loki [datasource](https://grafana.com/docs/grafana/latest/datasources/loki/) already configured.

![Grafana Explore](grafana-query-builder.png)
{{< figure src="/media/docs/loki/grafana-query-builder.png" caption="Query builder in Grafana Explore" alt="Grafana Explore">}}

1. From the Grafana main menu, click the **Explore** icon (1) to launch the Explore tab. To learn more about Explore, refer the [Explore](https://grafana.com/docs/grafana/latest/explore/) documentation.

Expand Down
2 changes: 1 addition & 1 deletion docs/sources/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ This API endpoint is usually used by Kubernetes-specific scale down automations
## Flush in-memory chunks and shut down

```
POST /ingester/shutdown
GET, POST /ingester/shutdown
```

`/ingester/shutdown` triggers a shutdown of the ingester and notably will _always_ flush any in memory chunks it holds.
Expand Down
10 changes: 10 additions & 0 deletions docs/sources/setup/install/helm/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@ null
},
"s3": {
"accessKeyId": null,
"backoff_config": {},
"endpoint": null,
"http_config": {},
"insecure": false,
Expand Down Expand Up @@ -2285,6 +2286,15 @@ null
"type": "s3"
}
</pre>
</td>
</tr>
<tr>
<td>loki.storage.s3.backoff_config</td>
<td>object</td>
<td>Check https://grafana.com/docs/loki/latest/configure/#s3_storage_config for more info on how to provide a backoff_config</td>
<td><pre lang="json">
{}
</pre>
</td>
</tr>
<tr>
Expand Down
7 changes: 6 additions & 1 deletion integration/loki_micro_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,16 @@ func TestMicroServicesIngestQuery(t *testing.T) {
assert.ElementsMatch(t, []map[string]string{{"job": "fake"}}, resp)
})

t.Run("stats error", func(t *testing.T) {
t.Run("series error", func(t *testing.T) {
_, err := cliQueryFrontend.Series(context.Background(), `{job="fake"}|= "search"`)
require.ErrorContains(t, err, "status code 400: only label matchers are supported")
})

t.Run("stats error", func(t *testing.T) {
_, err := cliQueryFrontend.Stats(context.Background(), `{job="fake"}|= "search"`)
require.ErrorContains(t, err, "status code 400: only label matchers are supported")
})

t.Run("per-request-limits", func(t *testing.T) {
queryLimitsPolicy := client.InjectHeadersOption(map[string][]string{querylimits.HTTPHeaderQueryLimitsKey: {`{"maxQueryLength": "1m"}`}})
cliQueryFrontendLimited := client.New(tenantID, "", tQueryFrontend.HTTPURL(), queryLimitsPolicy)
Expand Down
38 changes: 37 additions & 1 deletion pkg/bloomcompactor/bloomcompactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"

"path/filepath"

"github.com/google/uuid"

"github.com/grafana/loki/pkg/bloomutils"
"github.com/grafana/loki/pkg/storage"
v1 "github.com/grafana/loki/pkg/storage/bloom/v1"
Expand Down Expand Up @@ -489,9 +493,23 @@ func (c *Compactor) runCompact(ctx context.Context, logger log.Logger, job Job,
return level.Error(logger).Log("msg", "failed to compact new chunks", "err", err)
}

archivePath := filepath.Join(c.cfg.WorkingDirectory, uuid.New().String())

blockToUpload, err := c.compressBloomBlock(storedBlock, archivePath, localDst, logger)
if err != nil {
level.Error(logger).Log("msg", "putting blocks to storage", "err", err)
return err
}
defer func() {
err = os.Remove(archivePath)
if err != nil {
level.Error(logger).Log("msg", "removing archive file", "err", err, "file", archivePath)
}
}()

// Do not change the signature of PutBlocks yet.
// Once block size is limited potentially, compactNewChunks will return multiple blocks, hence a list is appropriate.
storedBlocks, err := c.bloomShipperClient.PutBlocks(ctx, []bloomshipper.Block{storedBlock})
storedBlocks, err := c.bloomShipperClient.PutBlocks(ctx, []bloomshipper.Block{blockToUpload})
if err != nil {
level.Error(logger).Log("msg", "putting blocks to storage", "err", err)
return err
Expand Down Expand Up @@ -539,3 +557,21 @@ func (c *Compactor) runCompact(ctx context.Context, logger log.Logger, job Job,
}
return nil
}

func (c *Compactor) compressBloomBlock(storedBlock bloomshipper.Block, archivePath, localDst string, logger log.Logger) (bloomshipper.Block, error) {
blockToUpload := bloomshipper.Block{}
archiveFile, err := os.Create(archivePath)
if err != nil {
return blockToUpload, err
}

err = v1.TarGz(archiveFile, v1.NewDirectoryBlockReader(localDst))
if err != nil {
level.Error(logger).Log("msg", "creating bloom block archive file", "err", err)
return blockToUpload, err
}

blockToUpload.BlockRef = storedBlock.BlockRef
blockToUpload.Data = archiveFile
return blockToUpload, nil
}
Loading

0 comments on commit ba306cf

Please sign in to comment.