Skip to content

Commit

Permalink
docs: Update README fluent-bit config for events (#108)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergiy Kulanov <sergiy_kulanov@epam.com>
  • Loading branch information
SergK committed Jul 8, 2024
1 parent e33abd8 commit fe9942e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
43 changes: 43 additions & 0 deletions add-ons/fluent-bit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,49 @@ It relies on the KubeRocketCI's OpenSearch chart for log storage and analysis, p

For further customization and to tailor the Fluent Bit configuration to your needs, please review the `values.yaml` file.

### Calculate duration for PipelineRuns and TaskRuns

To calculate the duration of PipelineRuns and TaskRuns, you can add a scripted field in OpenSearch Dashboards.

Navigate to the **Management** section in OpenSearch Dashboards.
Go to Stack **Management** > **Index Patterns**.
Select the index pattern that contains your data (e.g., logstash-cloudevents-*).
Find and click on the **Scripted fields** tab, then click on **Add scripted field**.
Fill in the **Name** for your field, for example, **duration**.
For the **Language**, ensure that painless is selected.
Set the Script type to **number**.
In the Script field, enter the following code:

```java
long startTimeMillis = 0;
long completionTimeMillis = 0;

// Check for pipelineRun times
if (doc.containsKey('pipelineRun.status.startTime') && !doc['pipelineRun.status.startTime'].empty) {
startTimeMillis = doc['pipelineRun.status.startTime'].value.getMillis();
}

if (doc.containsKey('pipelineRun.status.completionTime') && !doc['pipelineRun.status.completionTime'].empty) {
completionTimeMillis = doc['pipelineRun.status.completionTime'].value.getMillis();
}

// Check for taskRun times if pipelineRun times aren't set
if (startTimeMillis == 0 && doc.containsKey('taskRun.status.startTime') && !doc['taskRun.status.startTime'].empty) {
startTimeMillis = doc['taskRun.status.startTime'].value.getMillis();
}

if (completionTimeMillis == 0 && doc.containsKey('taskRun.status.completionTime') && !doc['taskRun.status.completionTime'].empty) {
completionTimeMillis = doc['taskRun.status.completionTime'].value.getMillis();
}

// Calculate duration in seconds if both times are available
if (startTimeMillis > 0 && completionTimeMillis > 0) {
return (completionTimeMillis - startTimeMillis) / 1000;
} else {
return 0; // Return 0 or some default value if the necessary fields are missing or incomplete
}
```

## Requirements

| Repository | Name | Version |
Expand Down
43 changes: 43 additions & 0 deletions add-ons/fluent-bit/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,49 @@ It relies on the KubeRocketCI's OpenSearch chart for log storage and analysis, p

For further customization and to tailor the Fluent Bit configuration to your needs, please review the `values.yaml` file.

### Calculate duration for PipelineRuns and TaskRuns

To calculate the duration of PipelineRuns and TaskRuns, you can add a scripted field in OpenSearch Dashboards.

Navigate to the **Management** section in OpenSearch Dashboards.
Go to Stack **Management** > **Index Patterns**.
Select the index pattern that contains your data (e.g., logstash-cloudevents-*).
Find and click on the **Scripted fields** tab, then click on **Add scripted field**.
Fill in the **Name** for your field, for example, **duration**.
For the **Language**, ensure that painless is selected.
Set the Script type to **number**.
In the Script field, enter the following code:

```java
long startTimeMillis = 0;
long completionTimeMillis = 0;

// Check for pipelineRun times
if (doc.containsKey('pipelineRun.status.startTime') && !doc['pipelineRun.status.startTime'].empty) {
startTimeMillis = doc['pipelineRun.status.startTime'].value.getMillis();
}

if (doc.containsKey('pipelineRun.status.completionTime') && !doc['pipelineRun.status.completionTime'].empty) {
completionTimeMillis = doc['pipelineRun.status.completionTime'].value.getMillis();
}

// Check for taskRun times if pipelineRun times aren't set
if (startTimeMillis == 0 && doc.containsKey('taskRun.status.startTime') && !doc['taskRun.status.startTime'].empty) {
startTimeMillis = doc['taskRun.status.startTime'].value.getMillis();
}

if (completionTimeMillis == 0 && doc.containsKey('taskRun.status.completionTime') && !doc['taskRun.status.completionTime'].empty) {
completionTimeMillis = doc['taskRun.status.completionTime'].value.getMillis();
}

// Calculate duration in seconds if both times are available
if (startTimeMillis > 0 && completionTimeMillis > 0) {
return (completionTimeMillis - startTimeMillis) / 1000;
} else {
return 0; // Return 0 or some default value if the necessary fields are missing or incomplete
}
```

{{ template "chart.maintainersSection" . }}

{{ template "chart.sourcesSection" . }}
Expand Down

0 comments on commit fe9942e

Please sign in to comment.