forked from open-telemetry/opentelemetry-log-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
file_input should not attempt to track lost files on windows (open-te…
…lemetry#366) * WIP - filelog receiver should not attempt to track lost files on windows * Pull os-specific file handle management into separate struct
- Loading branch information
1 parent
fcea3af
commit 3df09ff
Showing
5 changed files
with
133 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package file | ||
|
||
import "context" | ||
|
||
type roller interface { | ||
roll(context.Context, []*Reader) | ||
cleanup() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build !windows | ||
// +build !windows | ||
|
||
package file | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
) | ||
|
||
type detectLostFiles struct { | ||
oldReaders []*Reader | ||
} | ||
|
||
func newRoller() roller { | ||
return &detectLostFiles{[]*Reader{}} | ||
} | ||
|
||
func (r *detectLostFiles) roll(ctx context.Context, readers []*Reader) { | ||
// Detect files that have been rotated out of matching pattern | ||
lostReaders := make([]*Reader, 0, len(r.oldReaders)) | ||
OUTER: | ||
for _, oldReader := range r.oldReaders { | ||
for _, reader := range readers { | ||
if reader.Fingerprint.StartsWith(oldReader.Fingerprint) { | ||
continue OUTER | ||
} | ||
} | ||
lostReaders = append(lostReaders, oldReader) | ||
} | ||
|
||
var lostWG sync.WaitGroup | ||
for _, reader := range lostReaders { | ||
lostWG.Add(1) | ||
go func(r *Reader) { | ||
defer lostWG.Done() | ||
r.ReadToEnd(ctx) | ||
}(reader) | ||
} | ||
lostWG.Wait() | ||
|
||
for _, reader := range r.oldReaders { | ||
reader.Close() | ||
} | ||
|
||
r.oldReaders = readers | ||
} | ||
|
||
func (r *detectLostFiles) cleanup() { | ||
for _, reader := range r.oldReaders { | ||
reader.Close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build windows | ||
// +build windows | ||
|
||
package file | ||
|
||
import "context" | ||
|
||
type closeImmediately struct{} | ||
|
||
func newRoller() roller { | ||
return &closeImmediately{} | ||
} | ||
|
||
func (r *closeImmediately) roll(_ context.Context, readers []*Reader) { | ||
for _, reader := range readers { | ||
reader.Close() | ||
} | ||
} | ||
|
||
func (r *closeImmediately) cleanup() { | ||
return | ||
} |