Automating Log Analysis And Troubleshooting With Palm Api
Automating Log Analysis and Troubleshooting with PaLM API
Automating Log Analysis and Troubleshooting with PaLM API
Hello Everyone!
Automating Log Analysis and Troubleshooting with PaLM API
Hello Everyone!
Google recently launched their Large Language Model, PaLM, and it is indeed an amazing piece of technology. In this blog, I will provide a detailed description of how we can use the power of PaLM APIs to automate log analysis and troubleshooting in your GitHub Actions workflows. This tool demonstrates the power and impact of tools like PaLM in the field of Automated software testing and QA.
Prerequisites
- PaLM API Key: PaLM API is currently available for public usage. You can grab your API key for the same from MakerSuite. This API key is one of the most critical requirements of developing this simple yet powerful tool.
- Python: We are going to use google-generativeai module provided by google. You can refer to the API docs for other languages as well.
- act: A CLI tool to run GitHub actions locally on your system. Removes the need to continuously push the updated code to a separate branch just to check the workflow run.
- Docker: Required to run act. Also required if you wish to write your GitHub action as a Docker container.
Let’s start coding!
Writing the Summary Generator Script
This small yet powerful script will be the core of our utility. We are going to use the google-generativeai module to write this script so be sure to install it in your virtual environment before diving into the main script.
First of all let’s gain access to our model!
Our script is going to take the path of the log file to be analyzed and the API key for accessing the PaLM API from the user. Now we need to tell our model what exactly is it designed to do. This is very important to make our model focus only on the important things, in our case, content of the log file.
For this we can prepare a prompt that goes as follows:
You can try other variations as well, it depends on what all you need the tool to analyze. In my case I did not want any fixes related to warnings so I had to instruct the model to only focus on errors and also to ensure that the file provided is a typical log file and not something else for example a python script. This part is the most simple and yet one of the most important piece of information given to the model.
Now we just need to extract the content of the file passed in by the user and pass it along with the prompt given above as:
You can also customize the parameters provided in the generate_text function, you can also explore other functions provided by PaLM in the official documentation.
This completes the core of our utility!
Let’s write some Actions
Now we are going to embed this script in a GitHub action and publish it on GitHub marketplace. GitHub allows you to write three type of actions:
- Docker based Actions : Package all the requirements in a single docker container
- JavaScript Actions
- Composite Actions : Bare bones method to write actions using Bash scripts
For this section, I will be using composite actions. However, we could also use docker based actions if we wanted to.
First we will write the action.yml file. This file contains all the metadata about our action i.e. all the required inputs and possible outputs, name, description etc.
In our case we need the API key which the user can provide using GitHub Repository secrets and path to the log file to be analyzed. So we will go with the following:
As you can see we have defined the input parameters and also added the feature to upload the analysis report as an artifact. Artifacts are used to store data in GitHub actions in workflow runs which are available for a duration of 90 days. We have a separate script named entrypoint.sh to ensure that all the required dependencies are installed.
To learn more about writing your own GitHub actions you can go here.
Bringing it all together
With all these components together we are now ready to publish our custom action! For this you’ll need to create a GitHub repository and push all the code. Once you push the code you’ll be greeted by a banner in the repository informing you that you can publish your action to GitHub marketplace. Make sure that you also have a README file to inform users on how to use your action in their workflows.
Finally let’s take a look at the output generated by our action for the following log:
The output:
As you can see the model not only summarized the errors but it also gave some amazing recommendations to fix the errors!
This file will be available in your action run as an artifact as shown in the image below:
Summary report generated in the PGWeb Testing Harness Suite by our Palm GitHub Action
Conclusion
In this blog, we saw how easy it is to leverage powerful tools like PaLM to automate tasks that might have taken hours and hours to set up earlier. I personally had to write a separate python script to process logs in one of my recent projects which you check here. This shows how PaLM can assist in fields like Software Testing and QA if used in the correct manner.
Thanks for reading!
By Akshat Jaimini on September 4, 2023.
Exported from Medium on March 25, 2025.