首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用opencensus python时出现路径不存在或无法访问错误

使用opencensus python时出现路径不存在或无法访问错误
EN

Stack Overflow用户
提问于 2021-07-26 17:15:10
回答 1查看 113关注 0票数 0

当我尝试在我的dockerized Django项目中集成opencensus python时,我得到了以下错误。

代码语言:javascript
复制
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中返回的,但是它意味着什么,我如何修复它?

EN

回答 1

Stack Overflow用户

发布于 2021-08-02 06:44:56

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

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

代码语言:javascript
复制
     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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68527299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档