0

当我尝试将 opencensus-python 集成到我的 dockerized Django 项目中时,出现以下错误。

ERROR: Path /tmp/opencensus-python-<hash-code>/2021-07-26T070705.948749-147e2037.blob@2021-07-26T070828.122386.lock does not exist or is inaccessible. 
ERROR: Path /tmp/opencensus-python-<hash-code>/2021-07-26T085046.693213-b80f5ca1.blob.tmp does not exist or is inaccessible.                                               

我做了一些搜索,发现返回了这个错误,_check_storage_size但这是什么意思,我该如何解决?

4

1 回答 1

0

由于找不到路径,这是OSError 。确保您以正确的格式分配路径,并且文件/文件夹具有读/写权限。还要确保在导出器配置中增加“'storage_max_size'”的值。

您可以参考此 Python 代码进行检查test_check_storage_size_error

     def put(self, data, lease_period=0):
            if not self._check_storage_size():
                return None
            blob = LocalFileBlob(os.path.join(
                self.path,
                '{}-{}.blob'.format(
                    _fmt(_now()),
                    '{:08x}'.format(random.getrandbits(32)),  # thread-safe random
                ),
            ))
            return blob.put(data, lease_period=lease_period)
    
    def _check_storage_size(self):
            size = 0
            for dirpath, dirnames, filenames in os.walk(self.path):
                for f in filenames:
                    fp = os.path.join(dirpath, f)
                    # skip if it is symbolic link
                    if not os.path.islink(fp):
                        try:
                            size += os.path.getsize(fp)
                        except OSError:
                            logger.error(
                                "Path %s does not exist or is inaccessible.", fp
                            )
                            continue
                        if size >= self.max_size:
                            logger.warning(
                                "Persistent storage max capacity has been "
                                "reached. Currently at %fKB. Telemetry will be "
                                "lost. Please consider increasing the value of "
                                "'storage_max_size' in exporter config.",
                                format(size/1024)
                            )
                            return False
            return True

def test_check_storage_size_error(self):
            input = (1, 2, 3)
            with LocalFileStorage(os.path.join(TEST_FOLDER, 'asd5'), 1) as stor:
                with mock.patch('os.path.getsize', side_effect=throw(OSError)):
                    stor.put(input)
                    with mock.patch('os.path.islink') as os_mock:
                        os_mock.return_value = True
                    self.assertTrue(stor._check_storage_size())

可以参考opencesus-python-storage.pyopencesus-python-test_storage.py

于 2021-08-02T06:44:55.897 回答