【问题标题】:Path does not exist or is inaccessible error when using opencensus-python使用 opencensus-python 时路径不存在或不可访问错误
【发布时间】:2021-10-02 05:47:13
【问题描述】:

当我尝试将 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中返回了这个错误,但这是什么意思,我该如何解决?

【问题讨论】:

    标签: python django azure azure-application-insights opencensus


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-11
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-28
      • 2013-07-10
      相关资源
      最近更新 更多