def process_web_request(self, request, path, params, fragment):
    options = dict(command_processor.get_global_options())
    options['services'] = ','.join(options.get('services', '[all]'))
    options.update(params)
    service_list = options.get('services', 'all').split(',')
    options['services'] = service_list
    data_map = self.__get_data_map(options)

    if accepts_html(request):
      content_type = 'text/html'
      by_service = self.service_map_to_html
      by_type = self.type_map_to_html
    else:
      content_type = 'text/plain'
      by_service = self.service_map_to_text
      by_type = self.type_map_to_text

    by = options.get('by', 'service')
    if by == 'service':
      content_data = by_service(data_map, params=params)
    else:
      content_data = by_type(data_map, params=params)

    if content_type == 'text/html':
      body = http_server.build_html_document(
          content_data, title='Current Metrics')
    else:
      body = content_data
    request.respond(200, {'ContentType': content_type}, body)
Exemple #2
0
    def process_web_request(self, request, path, params, fragment):
        options = dict(command_processor.get_global_options())
        options['services'] = ','.join(options.get('services', '[all]'))
        options.update(params)
        service_list = options.get('services', 'all').split(',')
        options['services'] = service_list
        data_map = self.__get_data_map(options)

        if accepts_html(request):
            content_type = 'text/html'
            by_service = self.service_map_to_html
            by_type = self.type_map_to_html
        else:
            content_type = 'text/plain'
            by_service = self.service_map_to_text
            by_type = self.type_map_to_text

        by = options.get('by', 'service')
        if by == 'service':
            content_data = by_service(data_map, params=params)
        else:
            content_data = by_type(data_map, params=params)

        if content_type == 'text/html':
            body = http_server.build_html_document(content_data,
                                                   title='Current Metrics')
        else:
            body = content_data
        request.respond(200, {'ContentType': content_type}, body)
    def process_web_request(self, request, path, params, fragment):
        options = dict(command_processor.get_global_options())
        options.update(params)
        catalog = spectator_client.get_source_catalog(options)
        data_map = self._get_data_map(catalog, options)

        if self.accepts_content_type(request, 'text/html'):
            content_type = 'text/html'
            by_service = self.service_map_to_html
            by_type = self.type_map_to_html
        else:
            content_type = 'text/plain'
            by_service = self.service_map_to_text
            by_type = self.type_map_to_text

        by = options.get('by', 'service')
        if by == 'service':
            content_data = by_service(data_map, params=params)
        else:
            content_data = by_type(data_map, params=params)

        if content_type == 'text/html':
            body = http_server.build_html_document(content_data,
                                                   title='Current Metrics')
        else:
            body = content_data
        request.respond(200, {'ContentType': content_type}, body)
Exemple #4
0
  def process_web_request(self, request, path, params, fragment):
    options = dict(get_global_options())
    options.update(params)

    surveyor = StackdriverSurveyor(options)
    descriptor_list = get_descriptor_list(options)

    begin_time = time.time()
    survey = surveyor.build_survey_from_descriptor_list(descriptor_list)
    survey_secs = time.time() - begin_time
    if str(params.get('delete_unused')).lower() == 'true':
      self.delete_unused(options, surveyor, survey)
    info_list = surveyor.survey_to_sorted_list(survey)

    footer = 'Survey Time = %.1f s' % survey_secs
    header = 'Activity during %s ... %s (%s)' % (
        surveyor.start_time, surveyor.end_time,
        SurveyInfo.to_days_since(surveyor.days_since))

    if self.accepts_content_type(request, 'text/html'):
      html = header + '<p>'
      html += self.survey_to_html(surveyor, info_list)
      html += '<br/>' + footer
      html_doc = http_server.build_html_document(
          html, title='Last Custom Descriptor Use')
      request.respond(200, {'ContentType': 'text/html'}, html_doc)
    elif self.accepts_content_type(request, 'application/json'):
      json_doc = json.JSONEncoder(indent=2).encode(info_list)
      request.respond(200, {'ContentType': 'application/json'}, json_doc)
    else:
      text = self.survey_to_text(info_list)
      text += '\n\n' + footer
      request.respond(200, {'ContentType': 'text/plain'}, text)
Exemple #5
0
    def process_commandline_request(self, options):
        type_map, service_tag_map, active_services = (
            self.__get_type_and_tag_map_and_active_services(options))

        params = strip_non_html_params(options)
        html = self.to_html(type_map, service_tag_map, active_services, params)
        html_doc = http_server.build_html_document(html, title='Metric Usage')
        self.output(options, html_doc)
Exemple #6
0
    def test_explore_custom_descriptors_default(self, mock_urlopen):
        klass = spectator_handlers.ExploreCustomDescriptorsHandler
        explore = klass(None, None, None)

        mock_urlopen.side_effect = [
            self.mock_gate_response, self.mock_clouddriver_response
        ]

        params = dict(self.options)
        params['services'] = 'clouddriver'

        explore.process_web_request(self.mock_request, '/explore', params, '')
        called_with = self.mock_request.respond.call_args[0]
        self.assertEqual(200, called_with[0])
        self.assertEqual({'ContentType': 'text/html'}, called_with[1])
        html = minimize_html(called_with[2])

        service_link = '<A href="/show?services={0}">{0}</A>'.format
        name_link = '<A href="/show?meterNameRegex={0}">{0}</A>'.format
        tag_link = '<A href="/explore?tagNameRegex={0}">{0}</A>'.format
        value_link = '<A href="/explore?tagValueRegex={0}">{0}</A>'.format

        expect_body = TABLE([
            TR(
                TH([
                    'Metric', 'Label',
                    service_link('clouddriver'),
                    service_link('gate')
                ])),
            TR(
                TD([name_link('controller.invocations')], rowspan=2),
                TD([
                    tag_link('controller'), '',
                    value_link('PipelineController')
                ])),
            TR(TD([tag_link('method'), '',
                   value_link('savePipeline')])),
            TR(
                TD([
                    name_link('jvm.buffer.memoryUsed'),
                    tag_link('id'),
                    ', '.join([value_link('direct'),
                               value_link('mapped')]),
                    ', '.join([value_link('direct'),
                               value_link('mapped')])
                ])),
            TR(TD([name_link('jvm.gc.maxDataSize'), '', 'n/a', 'n/a'])),
            TR(
                TD([
                    name_link('tasks'),
                    tag_link('success'),
                    value_link('true'), ''
                ])),
        ])
        expect = minimize_html(
            http_server.build_html_document(expect_body, 'Metric Usage'))
        self.assertEqual(expect, html)
  def process_commandline_request(self, options):
    type_map, service_tag_map, active_services = (
        self.__get_type_and_tag_map_and_active_services(options))

    params = strip_non_html_params(options)
    html = self.to_html(type_map, service_tag_map, active_services, params)
    html_doc = http_server.build_html_document(
        html, title='Metric Usage')
    self.output(options, html_doc)
    def process_web_request(self, request, path, params, fragment):
        options = dict(command_processor.get_global_options())
        options.update(params)
        catalog = spectator_client.get_source_catalog(options)

        type_map, service_tag_map, active_services = (
            self.__get_type_and_tag_map_and_active_services(catalog, options))

        params = strip_non_html_params(options)
        html = self.to_html(type_map, service_tag_map, active_services, params)
        html_doc = http_server.build_html_document(html, title='Metric Usage')
        request.respond(200, {'ContentType': 'text/html'}, html_doc)
Exemple #9
0
  def process_commandline_request(self, options):
    catalog = spectator_client.get_source_catalog(
        config_dir=options['config_dir'])
    type_map, service_tag_map, active_services = (
        self.__get_type_and_tag_map_and_active_services(
            catalog, options))

    params = strip_non_html_params(options)
    html = self.to_html(type_map, service_tag_map, active_services, params)
    html_doc = http_server.build_html_document(
        html, title='Metric Usage')
    self.output(options, html_doc)
Exemple #10
0
  def process_web_request(self, request, path, params, fragment):
    options = dict(command_processor.get_global_options())
    options['disable_metric_filter'] = True
    options.update(params)
    spectator = self.make_spectator_client(options)
    catalog = spectator_client.get_source_catalog(options)
    service_map = spectator.scan_by_service(catalog, options)

    yaml_dict = self.process_service_map(service_map)
    html = '<pre>%s</pre>' % encode_yaml(yaml_dict)
    html_doc = http_server.build_html_document(
        html, title='Inferred Meter Specs')
    request.respond(200, {'ContentType': 'application/html'}, html_doc)
    def process_web_request(self, request, path, params, fragment):
        descriptor_list = self.__get_descriptor_list(params)

        if accepts_content_type(request, 'text/html'):
            html = self.descriptors_to_html(descriptor_list)
            html_doc = http_server.build_html_document(
                html, title='Custom Descriptors')
            request.respond(200, {'ContentType': 'text/html'}, html_doc)
        elif accepts_content_type(request, 'application/json'):
            json_doc = json.JSONEncoder(indent=2).encode(descriptor_list)
            request.respond(200, {'ContentType': 'application/json'}, json_doc)
        else:
            text = self.descriptors_to_text(descriptor_list)
            request.respond(200, {'ContentType': 'text/plain'}, text)
  def process_web_request(self, request, path, params, fragment):
    descriptor_list = self.__get_descriptor_list(params)

    if accepts_content_type(request, 'text/html'):
      html = self.descriptors_to_html(descriptor_list)
      html_doc = http_server.build_html_document(
          html, title='Custom Descriptors')
      request.respond(200, {'ContentType': 'text/html'}, html_doc)
    elif accepts_content_type(request, 'application/json'):
      json_doc = json.JSONEncoder(indent=2).encode(descriptor_list)
      request.respond(200, {'ContentType': 'application/json'}, json_doc)
    else:
      text = self.descriptors_to_text(descriptor_list)
      request.respond(200, {'ContentType': 'text/plain'}, text)
Exemple #13
0
    def process_web_request(self, request, path, params, fragment):
        options = dict(command_processor.get_global_options())
        options['services'] = ','.join(options.get('services', '[all]'))
        options.update(params)
        service_list = options.get('services', 'all').split(',')
        options['services'] = service_list

        type_map, service_tag_map, active_services = (
            self.__get_type_and_tag_map_and_active_services(options))

        params = strip_non_html_params(options)
        html = self.to_html(type_map, service_tag_map, active_services, params)
        html_doc = http_server.build_html_document(html, title='Metric Usage')
        request.respond(200, {'ContentType': 'text/html'}, html_doc)
  def test_explore_custom_descriptors_default(self, mock_urlopen):
    klass = spectator_handlers.ExploreCustomDescriptorsHandler
    explore = klass(None, None, None)

    mock_urlopen.side_effect = [self.mock_clouddriver_response,
                                self.mock_gate_response]

    params = dict(self.options)
    params['services'] = ','.join(params['services'])

    explore.process_web_request(self.mock_request, '/explore', params, '')
    called_with = self.mock_request.respond.call_args[0]
    self.assertEqual(200, called_with[0])
    self.assertEqual({'ContentType': 'text/html'}, called_with[1])
    html = minimize_html(called_with[2])

    service_link = '<A href="/show?services={0}">{0}</A>'.format
    name_link = '<A href="/show?meterNameRegex={0}">{0}</A>'.format
    tag_link = '<A href="/explore?tagNameRegex={0}">{0}</A>'.format
    value_link = '<A href="/explore?tagValueRegex={0}">{0}</A>'.format

    expect_body = TABLE([
        TR(TH(['Metric',
               'Label',
               service_link('clouddriver'),
               service_link('gate')])),
        TR(TD([name_link('controller.invocations')], rowspan=2),
           TD([tag_link('controller'),
               '',
               value_link('PipelineController')])),
        TR(TD([tag_link('method'),
               '',
               value_link('savePipeline')])),
        TR(TD([name_link('jvm.buffer.memoryUsed'),
               tag_link('id'),
               ', '.join([value_link('direct'), value_link('mapped')]),
               ', '.join([value_link('direct'), value_link('mapped')])])),
        TR(TD([name_link('jvm.gc.maxDataSize'),
               '',
               'n/a',
               'n/a'])),
        TR(TD([name_link('tasks'),
               tag_link('success'),
               value_link('true'),
               ''])),
    ])
    expect = minimize_html(
        http_server.build_html_document(expect_body, 'Metric Usage'))
    self.assertEqual(expect, html)
Exemple #15
0
    def process_web_request(self, request, path, params, fragment):
        """Implements CommandHandler."""
        query = self.params_to_query(params)
        rows = [(handler.url_path, handler.description)
                for handler in self.__all_handlers]
        row_html = [('<tr>'
                     '<td><A href="{path}{params}">{path}</A></td>'
                     '<td>{info}</td>'
                     '</tr>'.format(path=row[0], params=query, info=row[1]))
                    for row in rows if row[0] is not None]

        html_body = '<table>\n{0}\n</table>'.format('\n'.join(row_html))
        html_doc = http_server.build_html_document(
            html_body, title='Spinnaker Metrics Administration')
        request.respond(200, {'ContentType': 'application/html'}, html_doc)
Exemple #16
0
  def process_web_request(self, request, path, params, fragment):
    """Implements CommandHandler."""
    query = self.params_to_query(params)
    rows = [(handler.url_path, handler.description)
            for handler in self.__all_handlers]
    row_html = [('<tr>'
                 '<td><A href="{path}{params}">{path}</A></td>'
                 '<td>{info}</td>'
                 '</tr>'.format(path=row[0], params=query, info=row[1]))
                for row in rows if row[0] is not None]

    html_body = '<table>\n{0}\n</table>'.format('\n'.join(row_html))
    html_doc = http_server.build_html_document(
        html_body, title='Spinnaker Metrics Administration')
    request.respond(200, {'ContentType': 'application/html'}, html_doc)
  def process_web_request(self, request, path, params, fragment):
    options = dict(command_processor.get_global_options())
    options['services'] = ','.join(options.get('services', '[all]'))
    options.update(params)
    service_list = options.get('services', 'all').split(',')
    options['services'] = service_list

    type_map, service_tag_map, active_services = (
        self.__get_type_and_tag_map_and_active_services(options))

    params = strip_non_html_params(options)
    html = self.to_html(type_map, service_tag_map, active_services, params)
    html_doc = http_server.build_html_document(
        html, title='Metric Usage')
    request.respond(200, {'ContentType': 'text/html'}, html_doc)
    def process_web_request(self, request, path, params, fragment):
        options = dict(get_global_options())
        options.update(params)
        descriptor_list = get_descriptor_list(options)
        metric_prefix = stackdriver_descriptors.determine_metric_prefix(
            options['stackdriver'])

        if self.accepts_content_type(request, 'text/html'):
            html = self.descriptors_to_html(metric_prefix, descriptor_list)
            html_doc = http_server.build_html_document(
                html, title='Custom Descriptors')
            request.respond(200, {'ContentType': 'text/html'}, html_doc)
        elif self.accepts_content_type(request, 'application/json'):
            json_doc = json.JSONEncoder(indent=2).encode(descriptor_list)
            request.respond(200, {'ContentType': 'application/json'}, json_doc)
        else:
            text = self.descriptors_to_text(metric_prefix, descriptor_list)
            request.respond(200, {'ContentType': 'text/plain'}, text)
  def make_response(self, request, as_html, action, title):
    """Create a response for the caller to ultimately send."""
    if as_html:
      html_rows = [('<tr><td>{0}</td><td>{1}</td></tr>\n'
                    .format(self.__get_name(i), self.batch_response[i]))
                   for i in range(self.__num_data)]
      html_body = '{0} {1} of {2}:\n<table>\n{3}\n</table>'.format(
          action, self.num_ok, self.__num_data, '\n'.join(html_rows))
      html_doc = http_server.build_html_document(
          html_body, title=title)
      return {'ContentType': 'text/html'}, html_doc

    text = ['{0}  {1}'.format(self.__get_name(self.__data_list[i]),
                              self.batch_response[i])
            for i in range(self.__num_data)]
    text.append('')
    text.append('{0} {1} of {2}'.format(action, self.num_ok, self.__num_data))
    return {'ContentType': 'text/plain'}, '\n'.join(text)
Exemple #20
0
  def make_response(self, request, as_html, action, title):
    """Create a response for the caller to ultimately send."""
    if as_html:
      html_rows = [('<tr><td>{0}</td><td>{1}</td></tr>\n'
                    .format(self.__get_name(self.__data_list[i]),
                            self.batch_response[i]))
                   for i in range(self.__num_data)]
      html_body = '{0} {1} of {2}:\n<table>\n{3}\n</table>'.format(
          action, self.num_ok, self.__num_data, '\n'.join(html_rows))
      html_doc = http_server.build_html_document(
          html_body, title=title)
      return {'ContentType': 'text/html'}, html_doc

    text = ['{0}  {1}'.format(self.__get_name(self.__data_list[i]),
                              self.batch_response[i])
            for i in range(self.__num_data)]
    text.append('')
    text.append('{0} {1} of {2}'.format(action, self.num_ok, self.__num_data))
    return {'ContentType': 'text/plain'}, '\n'.join(text)
    def process_web_request(self, request, path, params, fragment):
        """Implements CommandHandler."""
        if str(params.get('clear_all')).lower() != 'true':
            html = textwrap.dedent("""\
          Clearing descriptors requires query parameter
          <code>clear_all=true</code>.
          <p/>
          <a href="{path}?clear_all=true">Yes, delete everything!</a>
      """)
            html_doc = http_server.build_html_document(
                html, title='Missing Parameters')
            request.respond(400, {'ContentType': 'text/html'}, html_doc)
            return

        options = dict(get_global_options())
        options.update(params)
        descriptor_list, processor = self.__do_clear(options)
        response_code = (httplib.OK if processor.num_ok == len(descriptor_list)
                         else httplib.INTERNAL_SERVER_ERROR)
        headers, body = processor.make_response(
            request, self.accepts_content_type(request, 'text/html'),
            'Deleted', 'Cleared Time Series')
        request.respond(response_code, headers, body)
    def process_web_request(self, request, path, params, fragment):
        """Implements CommandHandler."""
        options = dict(get_global_options())
        options.update(params)

        if str(params.get('clear_all')).lower() != 'true':
            stackdriver = stackdriver_service.make_service(options)
            audit_results = stackdriver_descriptors.AuditResults(stackdriver)
            descriptor_list = audit_results.descriptor_map.values()
            descriptor_html = '\n<li> '.join(item['type']
                                             for item in descriptor_list)
            html = textwrap.dedent("""\
          Clearing descriptors requires query parameter
          <code>clear_all=true</code>.
          <p/>
          Here are the {count} custom descriptors:
          <ul>
          <li>{descriptors}
          </ul>
          <p/>
          <a href="{path}?clear_all=true">Yes, delete everything!</a>
      """.format(count=len(descriptor_list),
                 descriptors=descriptor_html,
                 path=path))

            html_doc = http_server.build_html_document(
                html, title='Missing Parameters')
            request.respond(400, {'ContentType': 'text/html'}, html_doc)
            return

        audit_results = self.__do_clear(options)
        response_code = (httplib.OK if audit_results.obsoleted_count == 0 else
                         httplib.INTERNAL_SERVER_ERROR)
        headers = {'Content-Type': 'text/plain'}
        body = audit_results_to_output(audit_results,
                                       "No custom descriptors to delete.")
        request.respond(response_code, headers, body)