#3 Port to fedora messaging
Closed 4 years ago by mohanboddu. Opened 4 years ago by mohanboddu.
releng/ mohanboddu/compose-tracker fedora-messaging  into  master

file modified
+69 -75
@@ -1,14 +1,12 @@ 

  #!/usr/bin/python3

  import datetime

- import fedmsg

+ import fedora_messaging 

In the end we don't need that import. It is not used :)

  import os

  import re

  import requests

  from libpagure import Pagure

  

- # Set fedmsg logging to not print warnings

  import logging

- logger = logging.getLogger('fedmsg')

  logger.setLevel(logging.ERROR)

  

  # Set local logging 
@@ -57,7 +55,7 @@ 

          text = "- No Task ID, look at log statement\n"

      return text

  

- def main():

+ def main(msg):

Would be good to add a comment or rename the function to make it clear that this is the callback used by fedora-messaging consume command.

      # grab token and connec to pagure

      token = os.getenv('PAGURE_TOKEN')

      if token:
@@ -74,74 +72,70 @@ 

      # Used for printing out a value when the day has changed

      date = datetime.date.today()

  

-     # Grab messages from fedmsg and process them as we go

-     logger.info("Starting listening for fedmsgs..") 

-     for name, endpoint, topic, msg in fedmsg.tail_messages():

-         logger.debug(topic)

- 

-         # Print out a log statement if the day has changed

-         today = datetime.date.today()

-         if today != date:

-             date = today

-             logger.info('mark')

- 

-         # https://apps.fedoraproject.org/datagrepper/raw?topic=org.fedoraproject.prod.pungi.compose.status.change&delta=100000

-         if "pungi.compose.status.change" in topic:

-             print('.', end='') # some sort of indicator of progress

-             print('.') # some sort of indicator of progress

- 

-             status = msg['msg']['status']

- 

-             # If we are in good states then continue

-             if status in ['FINISHED', 'STARTED']:

-                 continue

- 

-             # We have a compose that either failed or had missing artifacts

-             # create a new issue.

-             title = msg['msg']['compose_id'] + ' ' + status

-             logfileurl = msg['msg']['location'] + '/../logs/global/pungi.global.log'

-             logger.info("%s\t%s" % (title, logfileurl))

- 

-             # variable to hold description for issue

-             content = "[pungi.global.log](%s)\n\n" % logfileurl

- 

-             # If we fail to get the log file contents then we'll just

-             # best effort put a message in the issue.

-             try:

-                 lines = requests.get(logfileurl).text.splitlines()

-             except:

-                 logger.info("Failed to retrieve log contents from server.. skipping analysis")

-                 content+= "Failed to retrieve log contents from server.. skipping analysis"

-                 lines = []

-                 pass

- 

-             for x in range(1, len(lines)):

-                 line = lines[x-1][20:]   # trim date off log lines

-                 nextline = lines[x][20:] # trim date off log lines

- 

-                 # If this is a [FAIL] line then we take it and the

-                 # next line and add them in markdown format. Also grab

-                 # the taskid if we can and print a hyperlink to koji

-                 if re.search('\[FAIL\]', line):

-                     content+= get_supporting_text(nextline)

-                     content+= "```\n%s\n%s\n```\n\n" % (line, nextline)

- 

-                 # If this is the Compose run failed line, then add it

-                 # to the description too

-                 if re.search('.*Compose run failed.*', line):

-                     content+= ("- Compose run failed because: %s\n" %

-                                             get_supporting_text(line))

-                     content+= "```\n%s\n```\n" % (line)

- 

-             logger.debug(content)

- 

-             # pull only part of the compose ID for the tag to set

-             tag = re.search('(.*)-\d{8}', msg['msg']['compose_id']).group(1)

-             #TODO figure out how to set tag on an issue

-             # Should be able to do this now https://pagure.io/libpagure/issue/31

- 

-             if token:

-                 pg.create_issue(title=title, content=content)

- 

- if __name__ == '__main__':

-     main()

+     # Grab messages from message bus and process them as we go

+     logger.info("Starting listening for messages on message bus..") 

+ 

+     msg = msg.body 

+     # Print out a log statement if the day has changed

+     today = datetime.date.today()

+     if today != date:

+         date = today

+         logger.info('mark')

+ 

+     # https://apps.fedoraproject.org/datagrepper/raw?topic=org.fedoraproject.prod.pungi.compose.status.change&delta=100000

+     if "pungi.compose.status.change" in msg.topic:

+         print('.', end='') # some sort of indicator of progress

+         print('.') # some sort of indicator of progress

+ 

+         status = msg['msg']['status']

+ 

+         # If we are in good states then continue

+         if status in ['FINISHED', 'STARTED']:

+             continue

+ 

+         # We have a compose that either failed or had missing artifacts

+         # create a new issue.

+         title = msg['msg']['compose_id'] + ' ' + status

+         logfileurl = msg['msg']['location'] + '/../logs/global/pungi.global.log'

+         logger.info("%s\t%s" % (title, logfileurl))

+ 

+         # variable to hold description for issue

+         content = "[pungi.global.log](%s)\n\n" % logfileurl

+ 

+         # If we fail to get the log file contents then we'll just

+         # best effort put a message in the issue.

+         try:

+             lines = requests.get(logfileurl).text.splitlines()

+         except:

+             logger.info("Failed to retrieve log contents from server.. skipping analysis")

+             content+= "Failed to retrieve log contents from server.. skipping analysis"

+             lines = []

+             pass

+ 

+         for x in range(1, len(lines)):

+             line = lines[x-1][20:]   # trim date off log lines

+             nextline = lines[x][20:] # trim date off log lines

+ 

+             # If this is a [FAIL] line then we take it and the

+             # next line and add them in markdown format. Also grab

+             # the taskid if we can and print a hyperlink to koji

+             if re.search('\[FAIL\]', line):

+                 content+= get_supporting_text(nextline)

+                 content+= "```\n%s\n%s\n```\n\n" % (line, nextline)

+ 

+             # If this is the Compose run failed line, then add it

+             # to the description too

+             if re.search('.*Compose run failed.*', line):

+                 content+= ("- Compose run failed because: %s\n" %

+                                         get_supporting_text(line))

+                 content+= "```\n%s\n```\n" % (line)

+ 

+         logger.debug(content)

+ 

+         # pull only part of the compose ID for the tag to set

+         tag = re.search('(.*)-\d{8}', msg['msg']['compose_id']).group(1)

+         #TODO figure out how to set tag on an issue

+         # Should be able to do this now https://pagure.io/libpagure/issue/31

+ 

+         if token:

+             pg.create_issue(title=title, content=content)

In the end we don't need that import. It is not used :)

Would be good to add a comment or rename the function to make it clear that this is the callback used by fedora-messaging consume command.

I think we also need a example of fedora-messaging config file (config.toml).

I think we also need a example of fedora-messaging config file (config.toml).

Yeah there are a few other things that would need to be changed. (i've got some of them in a local branch). I'm interested in some of the discussion that will happen upstream on those issues before we move forward.

@mohanboddu @cverna - there is a version of this over in https://pagure.io/releng/compose-tracker/pull-request/5 - i'm testing it out - going to let it run tonight and see if it works. LMK what you think

Pull-Request has been closed by mohanboddu

4 years ago
Metadata