(self, url, object_path, service_name, tags, *args, **kwargs)
Query the given URL and return the response
Query the given URL and return the response
Query the given URL and return the response
def _rest_request(self, url, object_path, service_name, tags, *args, **kwargs):
        """
        Query the given URL and return the response
        """
        service_check_tags = ['url:%s' % self._get_url_base(url)] + tags

        if object_path:
            url = self._join_url_dir(url, object_path)

        # Add args to the url
        if args:
            for directory in args:
                url = self._join_url_dir(url, directory)

        # Add proxyapproved=True if we already have the proxy cookie
        if self.proxy_redirect_cookies:
            kwargs["proxyapproved"] = 'true'

        # Add kwargs as arguments
        if kwargs:
            query = '&'.join(['{0}={1}'.format(key, value) for key, value in iteritems(kwargs)])
            url = urljoin(url, '?' + query)

        try:
            self.log.debug('Spark check URL: %s', url)
            response = self.http.get(url, cookies=self.proxy_redirect_cookies)
            response.raise_for_status()
            content = response.text
            proxy_redirect_url = self._parse_proxy_redirect_url(content)
            if proxy_redirect_url:
                self.proxy_redirect_cookies = response.cookies
                # When using a proxy and the remote user is different that the current user
                # spark will display an html warning page.
                # This page displays a redirect link (which appends `proxyapproved=true`) and also
                # sets a cookie to the current http session. Let's follow the link.
                # https://github.com/apache/hadoop/blob/2064ca015d1584263aac0cc20c60b925a3aff612/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServlet.java#L368
                response = self.http.get(proxy_redirect_url, cookies=self.proxy_redirect_cookies)
                response.raise_for_status()

        except Timeout as e:
            self.service_check(
                service_name,
                AgentCheck.CRITICAL,
                tags=service_check_tags,
                message='Request timeout: {0}, {1}'.format(url, e),
            )
            raise

        except (HTTPError, InvalidURL, ConnectionError) as e:
            self.service_check(
                service_name,
                AgentCheck.CRITICAL,
                tags=service_check_tags,
                message='Request failed: {0}, {1}'.format(url, e),
            )
            raise

        except ValueError as e:
            self.service_check(service_name, AgentCheck.CRITICAL, tags=service_check_tags, message=str(e))
            raise

        else:
            return response
def _rest_request ( self , url , object_path , service_name , tags , * args , * * kwargs ) : service_check_tags = [ 'url:%s' % self . _get_url_base ( url ) ] + tags if object_path : url = self . _join_url_dir ( url , object_path ) # Add args to the url if args : for directory in args : url = self . _join_url_dir ( url , directory ) # Add proxyapproved=True if we already have the proxy cookie if self . proxy_redirect_cookies : kwargs [ "proxyapproved" ] = 'true' # Add kwargs as arguments if kwargs : query = '&' . join ( [ '{0}={1}' . format ( key , value ) for key , value in iteritems ( kwargs ) ] ) url = urljoin ( url , '?' + query ) try : self . log . debug ( 'Spark check URL: %s' , url ) response = self . http . get ( url , cookies = self . proxy_redirect_cookies ) response . raise_for_status ( ) content = response . text proxy_redirect_url = self . _parse_proxy_redirect_url ( content ) if proxy_redirect_url : self . proxy_redirect_cookies = response . cookies # When using a proxy and the remote user is different that the current user # spark will display an html warning page. # This page displays a redirect link (which appends `proxyapproved=true`) and also # sets a cookie to the current http session. Let's follow the link. # https://github.com/apache/hadoop/blob/2064ca015d1584263aac0cc20c60b925a3aff612/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServlet.java#L368 response = self . http . get ( proxy_redirect_url , cookies = self . proxy_redirect_cookies ) response . raise_for_status ( ) except Timeout as e : self . service_check ( service_name , AgentCheck . CRITICAL , tags = service_check_tags , message = 'Request timeout: {0}, {1}' . format ( url , e ) , ) raise except ( HTTPError , InvalidURL , ConnectionError ) as e : self . service_check ( service_name , AgentCheck . CRITICAL , tags = service_check_tags , message = 'Request failed: {0}, {1}' . format ( url , e ) , ) raise except ValueError as e : self . service_check ( service_name , AgentCheck . CRITICAL , tags = service_check_tags , message = str ( e ) ) raise else : return response