little-cui closed pull request #309: SCB-389 SC does not re-create the tracing file. URL: https://github.com/apache/incubator-servicecomb-service-center/pull/309
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/server/plugin/infra/tracing/buildin/file_collector.go b/server/plugin/infra/tracing/buildin/file_collector.go index b61b8c2e..a10fc292 100644 --- a/server/plugin/infra/tracing/buildin/file_collector.go +++ b/server/plugin/infra/tracing/buildin/file_collector.go @@ -51,6 +51,12 @@ func (f *FileCollector) write(batch []*zipkincore.Span) (c int) { if len(batch) == 0 { return } + + if err := f.checkFile(); err != nil { + util.Logger().Errorf(err, "check tracing file failed") + return + } + newLine := [...]byte{'\n'} w := bufio.NewWriter(f.Fd) for _, span := range batch { @@ -70,6 +76,30 @@ func (f *FileCollector) write(batch []*zipkincore.Span) (c int) { return } +func (f *FileCollector) checkFile() error { + if util.PathExist(f.Fd.Name()) { + return nil + } + + stat, err := f.Fd.Stat() + if err != nil { + return fmt.Errorf("stat %s: %s", f.Fd.Name(), err) + } + + util.Logger().Warnf(nil, "tracing file %s does not exist, re-create one", f.Fd.Name()) + fd, err := os.OpenFile(f.Fd.Name(), os.O_APPEND|os.O_CREATE|os.O_RDWR, stat.Mode()) + if err != nil { + return fmt.Errorf("open %s: %s", f.Fd.Name(), err) + } + + var old *os.File + f.Fd, old = fd, f.Fd + if err := old.Close(); err != nil { + util.Logger().Errorf(err, "close %s", f.Fd.Name()) + } + return nil +} + func (f *FileCollector) loop(stopCh <-chan struct{}) { var ( batch []*zipkincore.Span ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services