Ejemplo n.º 1
0
from flask import current_app
from flask import request
from requests import post

from api.metrics import outbound_http_response_time
from app import IDENTITY_HEADER
from app import inventory_config
from app import REQUEST_ID_HEADER
from app import UNKNOWN_REQUEST_ID_VALUE
from app.culling import staleness_to_conditions

__all__ = ("graphql_query", "pagination_params", "staleness_filter",
           "string_contains", "string_contains_lc", "url")

logger = getLogger("graphql")
outbound_http_metric = outbound_http_response_time.labels("xjoin")


def check_pagination(offset, total):
    if total and offset >= total:
        abort(404)  # Analogous to flask_sqlalchemy.BaseQuery.paginate


def graphql_query(query_string, variables, failure_logger):
    url_ = url()
    logger.info("QUERY: URL %s; query %s, variables %s", url_, query_string,
                variables)
    payload = {"query": query_string, "variables": variables}

    with outbound_http_metric.time():
        response = post(url_, json=payload, headers=_forwarded_headers())
Ejemplo n.º 2
0
from app import inventory_config
from app import Permission
from app import REQUEST_ID_HEADER
from app import UNKNOWN_REQUEST_ID_VALUE
from app.auth import get_current_identity
from app.instrumentation import rbac_failure
from app.instrumentation import rbac_permission_denied
from app.logging import get_logger

logger = get_logger(__name__)

ROUTE = "/api/rbac/v1/access/?application=inventory"
CHECKED_TYPE = "User"
RETRY_STATUSES = [500, 502, 503, 504]

outbound_http_metric = outbound_http_response_time.labels("rbac")


def rbac_url():
    return inventory_config().rbac_endpoint + ROUTE


def get_rbac_permissions():
    request_header = {
        IDENTITY_HEADER:
        request.headers[IDENTITY_HEADER],
        REQUEST_ID_HEADER:
        request.headers.get(REQUEST_ID_HEADER, UNKNOWN_REQUEST_ID_VALUE),
    }

    request_session = Session()
from lib.metrics import pendo_fetching_failure


__all__ = ("main", "run")

PROMETHEUS_JOB = "inventory-pendo-syncher"
LOGGER_NAME = "inventory_pendo_syncher"
COLLECTED_METRICS = (pendo_fetching_failure,)
RUNTIME_ENVIRONMENT = RuntimeEnvironment.PENDO_JOB

PENDO_ROUTE = "/metadata/account/custom/value"
KEY_HEADER = "x-pendo-integration-key"
CONTENT_TYPE_HEADER = "content-type"
RETRY_STATUSES = [408, 500, 502, 503, 504]

outbound_http_metric = outbound_http_response_time.labels("pendo")


def _init_config():
    config = Config(RUNTIME_ENVIRONMENT)
    config.log_configuration()
    return config


def _init_db(config):
    engine = create_engine(config.db_uri)
    return sessionmaker(bind=engine)


def _prometheus_job(namespace):
    return f"{PROMETHEUS_JOB}-{namespace}" if namespace else PROMETHEUS_JOB