Skip to content

Commit

Permalink
metrics_payload
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Aug 16, 2024
1 parent 26d2951 commit fa5ba3c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
58 changes: 57 additions & 1 deletion docs/reporters/ApiReporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,63 @@ API_REPORTER_BEARER_TOKEN=DDHGHfgfgjfhQESRDTHFKGKHFswgFHDHGDH
Example of logs sent to Loki:

```json
TODO
{
"streams": [
{
"stream": {
"source": "MegaLinter",
"gitRepoName": "megalinter",
"gitBranchName": "alpha",
"gitIdentifier": "megalinter/alpha",
"orgIdentifier": "alpha",
"descriptor": "API",
"linter": "spectral",
"linterKey": "API_SPECTRAL"
},
"values": [
[
"1723831050362439098",
"{\"linterDocUrl\": \"https://megalinter.io/latest/descriptors/api_spectral\", \"jobUrl\": \"\", \"severity\": \"success\", \"severityIcon\": \"\\u2705\", \"cliLintMode\": \"file\", \"numberFilesFound\": 1, \"numberErrorsFound\": 0, \"elapsedTime\": 1.54}"
]
]
},
{
"stream": {
"source": "MegaLinter",
"gitRepoName": "megalinter",
"gitBranchName": "alpha",
"gitIdentifier": "megalinter/alpha",
"orgIdentifier": "alpha",
"descriptor": "BASH",
"linter": "shellcheck",
"linterKey": "BASH_SHELLCHECK"
},
"values": [
[
"1723831050362439098",
"{\"linterDocUrl\": \"https://megalinter.io/latest/descriptors/bash_shellcheck\", \"jobUrl\": \"\", \"severity\": \"success\", \"severityIcon\": \"\\u2705\", \"cliLintMode\": \"list_of_files\", \"numberFilesFound\": 5, \"numberErrorsFound\": 0, \"elapsedTime\": 0.14}"
]
]
},
{
"stream": {
"source": "MegaLinter",
"gitRepoName": "megalinter",
"gitBranchName": "alpha",
"gitIdentifier": "megalinter/alpha",
"orgIdentifier": "alpha",
"descriptor": "MARKDOWN",
"linter": "markdownlint",
"linterKey": "MARKDOWN_MARKDOWNLINT"
},
"values": [
[
"1723831050362439098",
"{\"linterDocUrl\": \"https://megalinter.io/alpha/descriptors/markdown_markdownlint\", \"jobUrl\": \"\", \"severity\": \"warning\", \"severityIcon\": \"\\u26a0\\ufe0f\", \"cliLintMode\": \"list_of_files\", \"numberFilesFound\": 264, \"numberErrorsFound\": 291, \"numberErrorsFixed\": 0, \"elapsedTime\": 30.55}"
]
]
}
}
```

## Metrics Configuration
Expand Down
6 changes: 3 additions & 3 deletions megalinter/reporters/ApiReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,18 @@ def send_to_metrics_api(self):
logging.info("[Api Reporter Metrics] Using Bearer Token")
try:
response = session.post(
self.api_metrics_url, headers=headers, json=self.payloadFormatted
self.api_metrics_url, headers=headers, json=self.metrics_payload
)
if 200 <= response.status_code < 300:
logging.info(
f"[Api Reporter Metrics] Successfully posted data to {self.api_metrics_url}"
)
if self.is_notif_api_debug_active():
logging.info("[Api Reporter Metrics] " + json.dumps(obj=self.payloadFormatted, indent=True))
logging.info("[Api Reporter Metrics] " + json.dumps(obj=self.metrics_payload, indent=True))
else:
logging.warning(
f"[Api Reporter Metrics] Error posting data to {self.api_metrics_url} ({response.status_code})\n"
f"[Api Reporter Metrics] API request: {json.dumps(obj=self.payloadFormatted, indent=True)}\n"
f"[Api Reporter Metrics] API request: {json.dumps(obj=self.metrics_payload, indent=True)}\n"
f"[Api Reporter Metrics] API response: {response.text}"
)
except ConnectionError as e:
Expand Down

0 comments on commit fa5ba3c

Please sign in to comment.