Skip to content

Commit 5126d5f

Browse files
authored
fix loki.source.file docs re legacy positions file (#3830)
1 parent 490a649 commit 5126d5f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

‎docs/sources/reference/components/loki/loki.source.file.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ You can use the `tail_from_end` argument when you want to tail a large file with
5252
When set to true, only new logs are read, ignoring the existing ones.
5353

5454
{{< admonition type="note" >}}
55-
The `legacy_positions_file` argument is used when you are transitioning from legacy. The legacy positions file is rewritten into the new format.
56-
This operation only occurs if the positions file doesn't exist and the `legacy_positions_file` is valid.
57-
After the configuration is successfully converted, the `legacy_positions_file` is deleted.
55+
The `legacy_positions_file` argument is used when you are transitioning from legacy. The legacy positions file is converted to the new format.
56+
This operation only occurs if the new positions file doesn't exist and the `legacy_positions_file` is valid.
5857
If you add any labels before `loki.source.file`, then the positions file conversion won't work.
5958
The legacy positions file didn't have a concept of labels in the positions file, so the conversion assumes no labels.
6059
{{< /admonition >}}

‎internal/component/common/loki/positions/positions.go‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import (
1515
"time"
1616

1717
"github.com/go-kit/log"
18-
"github.com/grafana/alloy/internal/runtime/logging/level"
1918
yaml "gopkg.in/yaml.v2"
19+
20+
"github.com/grafana/alloy/internal/runtime/logging/level"
2021
)
2122

2223
const (
@@ -106,14 +107,15 @@ type LegacyFile struct {
106107
// 2. There is a file at the legacy path and that it is valid yaml
107108
func ConvertLegacyPositionsFile(legacyPath, newPath string, l log.Logger) {
108109
legacyPositions := readLegacyFile(legacyPath, l)
109-
// LegacyPositions did not exist or was invalid so return.
110+
// legacyPositions did not exist or was invalid so return.
110111
if legacyPositions == nil {
112+
level.Info(l).Log("msg", "will not convert the legacy positions file as it is not valid or does not exist", "legacy_path", legacyPath)
111113
return
112114
}
113115
fi, err := os.Stat(newPath)
114116
// If the newpath exists, then don't convert.
115117
if err == nil && fi.Size() > 0 {
116-
level.Info(l).Log("msg", "new positions file already exists", "path", newPath)
118+
level.Info(l).Log("msg", "will not convert the legacy positions file as the new positions file already exists", "path", newPath)
117119
return
118120
}
119121

@@ -125,11 +127,11 @@ func ConvertLegacyPositionsFile(legacyPath, newPath string, l log.Logger) {
125127
Labels: "{}",
126128
}] = v
127129
}
128-
// After conversion remove the file.
129130
err = writePositionFile(newPath, newPositions)
130131
if err != nil {
131-
level.Error(l).Log("msg", "error writing new positions file from legacy", "path", newPath, "error", err)
132+
level.Error(l).Log("msg", "error writing new positions file converted from legacy", "path", newPath, "error", err)
132133
}
134+
level.Info(l).Log("msg", "successfully converted legacy positions file to the new format", "path", newPath, "legacy_path", legacyPath)
133135
}
134136

135137
func readLegacyFile(legacyPath string, l log.Logger) *LegacyFile {

0 commit comments

Comments
 (0)