Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📢 New MegaLinter v8 release, with Grafana ! #3913

Open
nvuillam opened this issue Aug 19, 2024 · 23 comments
Open

📢 New MegaLinter v8 release, with Grafana ! #3913

nvuillam opened this issue Aug 19, 2024 · 23 comments
Labels
breaking This is a large fundamental change help wanted Extra attention is needed nostale This issue or pull request is not stale, keep it open question Further information is requested

Comments

@nvuillam
Copy link
Member

nvuillam commented Aug 19, 2024

Run npx mega-linter-runner@latest --upgrade to upgrade to MegaLinter v8 :)

You can see release notes

If you are a Grafana expert and would like to help by configuring some great Dashboards using MegaLinter Prometheus Metrics and Loki logs, please contact me :)

If you are not a Grafana expert but have ideas about some relevant Dashboards we could create, please post an issue :)

If you see any problem with MegaLinter v8, please post here so it will be processed in priority :)

Video presentation:

Upgrade to v8 Video

LinkedIn post to like & share :)

@nvuillam nvuillam added the question Further information is requested label Aug 19, 2024
@nvuillam nvuillam pinned this issue Aug 19, 2024
@nvuillam nvuillam added breaking This is a large fundamental change help wanted Extra attention is needed nostale This issue or pull request is not stale, keep it open labels Aug 19, 2024
@nvuillam nvuillam changed the title New MegaLinter v8 release, with Grafana ! 📢 New MegaLinter v8 release, with Grafana ! Aug 19, 2024
@practicalli-johnny
Copy link
Contributor

When running Megalinter GitHub workflow, should there be output from the API_REPORTER reporter showing a message that logs were sent to Grafana?

I have followed the API Reporter(Grafana) guide but Grafana is not showing any log or metric information received when run as a GitHub action. I get "No data" in the Grafana dashboards provided by Megalinter. The Grafana dashboard home pages reports 0 (zero) for Metrics and Logs.

Am I unsure where this is failing as I do not see logs in the Megalinter output, even with API_REPORTER_DEBUG: true

I had created Repository secrets as I want to use Grafana dashboards for multiple repositories. I will check if that is the cause of the fail (but I dont see errors in the log)

Example project created from the MegaLinter docs (public GitHub repo):
https://github.com/practicalli/megalinter-test

NOTE: I've tried this on three separate GitHub repositories and the bearer token rather than basic auth, but all with the same results :(

@nvuillam
Copy link
Member Author

@practicalli-johnny it seems that nothing is sent to Grafana :(
You can use Grafana dashboards for multiple repos, they are build for that :)

But... I think your API_REPORTER is not active, otherwise you would see such logs

image

(source: https://github.com/oxsecurity/megalinter/actions/runs/10949911462/job/30404111491 )

After checking your config & logs... it looks good, so I must be missing something... I investigate :)

image

nvuillam added a commit that referenced this issue Sep 23, 2024
nvuillam added a commit that referenced this issue Sep 23, 2024
* Add debug traces to investigate reporters activation

Related to #3913

* Fix

* fix

* [MegaLinter] Apply linters fixes

---------

Co-authored-by: nvuillam <[email protected]>
@nvuillam
Copy link
Member Author

I added some debug outputs to help investigate

@practicalli-johnny please could you try with beta version and LOG_LEVEL: DEBUG then share the job execution link ? :)

@practicalli-johnny
Copy link
Contributor

Added LOG_LEVEL: DEBUG to the megalinter.yaml file and updated the Megalinter GitHub workflow to use @beta

uses: oxsecurity/megalinter/flavors/java@beta

GitHub actions workflow output: no data in Grafana dashboard.

I will try the main megalinter image rather than the java flavour.

@nvuillam
Copy link
Member Author

It should work the same with any flavor :'(

@nvuillam
Copy link
Member Author

@practicalli-johnny I don't understand why I can't find any [Reporters] in the log :'(

image

Please can you try to add the LOG_LEVEL: true directly in the Github workflow variables and not the .mega-linter.yml ?

@practicalli-johnny
Copy link
Contributor

practicalli-johnny commented Sep 24, 2024

Updated LOG_LEVEL to be only in the GitHub Workflow yaml file.

GitHub Workflow log

There is a log entry now about API REPORTER, but no data in Grafana :( - Edit: I only looked at the Grafana home page (which reports zero logs) and not the dashboards which were probably working - the dashboards do now work.

[Api Reporter Metrics] Using Basic Auth
  Starting new HTTPS connection (1): influx-prod-24-prod-eu-west-2.grafana.net:443
  [https://influx-prod-24-prod-eu-west-2.grafana.net:443](https://influx-prod-24-prod-eu-west-2.grafana.net/) "POST /api/v1/push/influx/write HTTP/11" 204 0
  [Api Reporter Metrics] Successfully posted data to ***
  [Api Reporter Metrics] linter_run,source=MegaLinter,orgIdentifier=main,gitIdentifier=megalinter-test/main,gitRepoName=megalinter-test,gitBranchName=main,descriptor=ACTION,linter=actionlint,linterKey=ACTION_ACTIONLINT numberErrorsFound=0,numberFilesFound=1,elapsedTime=0.02

@nvuillam
Copy link
Member Author

@practicalli-johnny according to the logs, the data is sent to Grafana :)

Please can you check is Explore -> Logs for events with source "MegaLinter" ?

image

@practicalli-johnny
Copy link
Contributor

practicalli-johnny commented Sep 24, 2024

Megalinter sent logs to Grafana at 9:50 this morning, so when I added LOG_LEVEL: DEBUG to the megalinter GitHub workflow yaml file.

image

The dashboards are now working too:

image

The home page of Grafana suggests the logs arent working, perhaps its because the number of logs is too low and being rounded down (or they are not looking at the right log source).

Later today I will change back to the java flavour of megalinter and confirm if logs are still being sent.

Thanks for all your help with diagnosing this issue. I will configure all the other Practicalli open source GitHub projects and experiment with the Grafana dashboards. I'll write up how I am using this all in a blog post later in the month. Thanks again.

@nvuillam
Copy link
Member Author

@practicalli-johnny great feedback, many thanks :)
If you have ideas of better dashboards than the very simple and ugly ones I created, I'd be delighted to see them ! :)

@nvuillam
Copy link
Member Author

nvuillam commented Sep 24, 2024

image

@practicalli-johnny Seing this one I wonder if you didn't select the wrong datasource when matching dashboards & sources at the import

Maybe selected prometheus instead of loki, or the contrary ?
On main dashboard you're supposed to have only one number by linter (the number of errors) , and the elapsed time is available in sub-dashboards after clicking on the button

@nabondance
Copy link
Contributor

Hi,
I was about to create an issue of the sending of metrics to Grafana not working on flavors.
Then I found this conversation and tried to solve my issue like you did (by adding ENABLE_LOGS=true), but it didn't worked, even on beta flavors.

Tell me if you'd prefer a new specific issue.

My findings so far:
using oxsecurity/megalinter/flavors/javascript@beta (or v8):
--> the workflow doesn't even try to send data
e.g. https://github.com/nabondance/Trailhead-Stats/actions/runs/11042265194/job/30674254975?pr=112

using oxsecurity/[email protected]:
--> the workflow send data and the grafana works perfectly
e.g. https://github.com/nabondance/Trailhead-Stats/actions/runs/11041968876/job/30673385205

The grafana log, with the only try without flavors sending data:
image

The env in the MegaLinter step:

          API_REPORTER: true
          API_REPORTER_URL: ${{ secrets.API_REPORTER_URL }}
          API_REPORTER_BASIC_AUTH_USERNAME:
            ${{ secrets.API_REPORTER_BASIC_AUTH_USERNAME }}
          API_REPORTER_BASIC_AUTH_PASSWORD:
            ${{ secrets.API_REPORTER_BASIC_AUTH_PASSWORD }}
          API_REPORTER_METRICS_URL: ${{ secrets.API_REPORTER_METRICS_URL }}
          API_REPORTER_METRICS_BASIC_AUTH_USERNAME:
            ${{ secrets.API_REPORTER_METRICS_BASIC_AUTH_USERNAME }}
          API_REPORTER_METRICS_BASIC_AUTH_PASSWORD:
            ${{ secrets.API_REPORTER_METRICS_BASIC_AUTH_PASSWORD }}
          API_REPORTER_DEBUG: true
          ENABLE_LOGS: true
          LOG_LEVEL: DEBUG

I really don't understand why it is not working when using a flavor and why the solution you found doesn't work for me.

I'm available if you have questions or need to test more things.

@nvuillam
Copy link
Member Author

@nabondance (coucou Nathan je t'ai reconnu 😄 ) > Please can you try with beta version of a flavor ?
There are new logs showing activation / deactivation of Reporters, it should help

@nabondance
Copy link
Contributor

nabondance commented Sep 26, 2024

(Bravo ! 😁)

Tried with the step:

- name: MegaLinter
        uses: oxsecurity/megalinter/flavors/javascript@beta
        id: ml
        env:
          VALIDATE_ALL_CODEBASE: true

          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

          # Uncomment to use ApiReporter (Grafana)
          API_REPORTER: true
          API_REPORTER_URL: ${{ secrets.API_REPORTER_URL }}
          API_REPORTER_BASIC_AUTH_USERNAME:
            ${{ secrets.API_REPORTER_BASIC_AUTH_USERNAME }}
          API_REPORTER_BASIC_AUTH_PASSWORD:
            ${{ secrets.API_REPORTER_BASIC_AUTH_PASSWORD }}
          API_REPORTER_METRICS_URL: ${{ secrets.API_REPORTER_METRICS_URL }}
          API_REPORTER_METRICS_BASIC_AUTH_USERNAME:
            ${{ secrets.API_REPORTER_METRICS_BASIC_AUTH_USERNAME }}
          API_REPORTER_METRICS_BASIC_AUTH_PASSWORD:
            ${{ secrets.API_REPORTER_METRICS_BASIC_AUTH_PASSWORD }}
          API_REPORTER_DEBUG: true
          ENABLE_LOGS: true
          LOG_LEVEL: DEBUG

The log with as much debug as possible:
https://github.com/nabondance/Trailhead-Stats/actions/runs/11042265194/job/30695747348
Still nothing trying to send data to loki/prom, the reporters doesn't start

I understand the goal and how to use the flavors, sadly I don't understand how they are generated, I can't help to find if it is related to the flavors themselves

Edit.
Additional information:
The token has been used at the time the workflow ran (but still no data log):
image

@practicalli-johnny
Copy link
Contributor

practicalli-johnny commented Sep 26, 2024

I recreated both dashboards and they seem correct now.

It seems there is an issue with the api reporter when using a megalinter flavor (java and documentation tested)

Using megalinter without a flavor publishes data to Grafana for both v8.0.0 and beta versions.

Using the Java flavor of megalinter, v8.0.0 or beta, the megalinter log does not include messages about the API reporter connecting.

The "Latest run" value in the DASH - ML Errors & Elapse dashboard does not show a date timestamp corresponding to a GitHub workflow run when the java flavour is used.

I also get Annotation warnings with the java flavour, which I do not get with the megalinter standard image
image

The documentation flavor (v8.0.0 or beta) seems to have the same issues as java flavor - no api message, no updated latest run and annotation warnings.

I havent tried any of these images via Docker as yet, only via a GitHub workflow.
All variants were tried on the same practicalli/megalinter-test GitHub repository. All uses: examples are include in the GitHub workflow yaml file.

@practicalli-johnny
Copy link
Contributor

One thing that seems easy to get tripped up on is that some linters will show "No Data" in the dashboard even if logs were pushed to Grafana. Looking at the first few sections of the "Errors & Elapse" dashboard can easily lead people to thinking that no logs have been pushed, if they dont scroll down many pages to a linter that does have data.

When only running a very small amount of linters it is easy to believe that no logs are being passed.

If the linters that have no data are collapsed then it is easier to see that new logs have been published on the "Errors & Elapse" dashboard.

I typically remove the "All" filter from the dashboard and add the few specific linter names I want to see. This makes it very easy to see new logs have been published, along with the time stamp.

Would a new dashboard be needed for each flavor? Or does the dashboard parse and display only the linters available from the last published logs? So if a specific flavor of megalinter is used, will it only show the linters on the "Errors & Elipse" dashboard?

It would be useful to share how the dashboards have currently been put together, as at first glance it not obvious what all the config means (I can make a few rough guesses). Ideally I'd like to define a dashboard that only has the linters I am most interested in, to avoid having to update filters or do lots of scrolling each time.

I have only been able to make API_REPORTER work with the default Megalinter version (flavor) which means disabling more specific linter in the config, e.g. Repository has more linters in the default Megalinter version)

@practicalli-johnny
Copy link
Contributor

Dashboard update:

Now the Grafana trial has expired and logs are only retained for 14 days, the dashboard is only showing the specific linters that have been run (and all have data to show).

This makes the provided megalinter Errors & Elapsed dashboard much simpler to understand, especially as I have only been pushing an API_REPORT from the one repository.

I wonder if there is additional configuration on the Megalinter dashboards to be scoped within a specific Git repository?

@nvuillam
Copy link
Member Author

nvuillam commented Oct 2, 2024

FYI i'm still struggling to find why flavors do not call ApiReporter 😨
That's kind of a great mystery... and the new limitations about Docker Hub for internal CI do not help, but I really plan to make it work for 8.1.0 :)

@vihangm
Copy link

vihangm commented Oct 2, 2024

I was checking the Changelog to check the version of the various linters, and while the Changelog says that golangci-lint was updated to v1.60.1, that isn't true for the cupcake flavor.
Any chance you can cut a patch release to fix it?

$ docker run --rm -it --entrypoint=/bin/golangci-lint docker.io/oxsecurity/megalinter-cupcake:v8 --version
golangci-lint has version 1.59.1 built with go1.22.3 from 1a55854a on 2024-06-09T18:08:33Z

$ docker run --rm -it --entrypoint=/bin/golangci-lint docker.io/oxsecurity/megalinter:v8 --version
golangci-lint has version 1.60.1 built with go1.23.0 from 3298c104 on 2024-08-14T01:15:05Z

@nvuillam
Copy link
Member Author

@nabondance @practicalli-johnny > now Grafana stats should be ok with latest v8.1.0, please can you confirm ? :)

@vihangm > should be ok now too for golanci-lint version :)

@nabondance
Copy link
Contributor

@nvuillam it is working with the javascript flavor in v8.1.0
Thank a lot for the fix and the feature 🙏

@practicalli-johnny
Copy link
Contributor

practicalli-johnny commented Oct 13, 2024

Yes, I can confirm the API_REPORTER is working with the Megalinter v8.1.0 Documentation flavor. I will try with the Java flavor later, but I'm confident it will work okay.

Megalinter Grafana dashboard- markdown report

Thanks for all the effort in bringing the API_REPORTER to Megalinter. I'll spend some time this month wiring up my repositories and experimenting with the Grafana dashboards.

Thanks again.

@nvuillam
Copy link
Member Author

Thank you all for your feedback :)

Can't wait to read your new Grafana dashboards suggestions 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This is a large fundamental change help wanted Extra attention is needed nostale This issue or pull request is not stale, keep it open question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants