Skip to content

Commit 199620b

Browse files
committed
User defined log config
1 parent 332d525 commit 199620b

File tree

5 files changed

+84
-33
lines changed

5 files changed

+84
-33
lines changed

docs/observability/README.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,14 @@ graph LR
6767

6868
Logs are a way to understand what is happening in your application. They are usually text-based and are often used for debugging. Since the format of logs is usually not standardized, it can be difficult to query and aggregate logs and thus we recommend using metrics for dashboards and alerting.
6969

70-
Logs are collected automatically by [fluentd][fluentd], stored in [Elasticsearch][elasticsearch] and made accessible via [Kibana][kibana].
71-
72-
[fluentd]: https://www.fluentd.org/
73-
[elasticsearch]: https://www.elastic.co/elasticsearch/
74-
[kibana]: https://www.elastic.co/kibana/
70+
Logs that are sent to console (`stdout`) are collected automatically and can be configured for persistent storage and querying in several ways.
7571

7672
```mermaid
7773
graph LR
78-
Application --stdout/stderr--> Fluentbit
79-
Fluentbit --> Elasticsearch
80-
Elasticsearch --> Kibana
74+
Application --stdout/stderr--> Router
75+
Router --> A[Secure Logs]
76+
Router --> B[Grafana Loki]
77+
Router --> C[Elastic / Kibana]
8178
```
8279

8380
[:octicons-arrow-right-24: Configure your logs](./logs/README.md)

docs/observability/logs/README.md

+79-25
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,76 @@
1-
# Logs
1+
# Application Logs
22

3-
## Logging
3+
## Purpose
44

5-
Configure your application to log to console \(stdout/stderr\), it will be scraped by [FluentD](https://www.fluentd.org/) running inside the cluster and sent to [Elasticsearch](https://www.elastic.co/products/elasticsearch) and made available via [Kibana](https://www.elastic.co/products/kibana). Visit our Kibana at [logs.adeo.no](https://logs.adeo.no/).
5+
Logs are a way to understand what is happening in your application. They are usually text-based and are often used for debugging. Since the format of logs is usually not standardized, it can be difficult to query and aggregate logs and thus we recommend using metrics for dashboards and alerting.
66

7-
If you want more information than just the log message \(loglevel, MDC, etc\), you should log in JSON format; the fields you provide will then be indexed.
7+
There are many types of logs, and they can be used for different purposes. Some logs are used for debugging, some are used for auditing, and some are used for security. Our primary use case for logs is to understand the flow of a request through a system.
88

9-
## Working with Kibana
9+
Application logs in nais is first and foremost a tool for developers to debug their applications. It is not intended to be used for auditing or security purposes. We do not condone writing sensitive information to application logs.
10+
11+
## Overview
12+
13+
Logs that are sent to console (also known as `stdout`) are collected automatically by an agent inside the cluster. This agent can be configured to send logs for persistent storage and querying based on team- and application specific configuration.
14+
15+
Logs must be written in JSON format *and* preferably following the [Elastic Common Schema](https://www.elastic.co/guide/en/ecs/current/ecs-reference.html) or [OpenTelemetry Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/).
16+
17+
```mermaid
18+
graph LR
19+
Application --stdout/stderr--> FluentD
20+
FluentD --> A[Secure Logs]
21+
FluentD --> B[Grafana Loki]
22+
FluentD --> C[Elastic / Kibana]
23+
```
24+
25+
[FluentD]: https://www.fluentd.org/
26+
27+
## Configuration
28+
29+
30+
31+
## Destinations
32+
33+
| Destination | ID | Description | Availability |
34+
| :-------------------------- | :------------ | :--------------------------------- | :----------- |
35+
| None | `none` | Logs are not collected. | All |
36+
| [Loki](#grafana-loki) | `loki` | Logs are available in Grafana. | All |
37+
| [Elastic](#elastic-kibana) | `elastic` | Logs are available in Kibana. | NAV-only |
38+
| [Secure Logs](#secure-logs) | `secure_logs` | Logs are stored in a secret place. | NAV-only |
39+
40+
## Grafana Loki
41+
42+
Grafana Loki is a log aggregation system inspired by Prometheus and integrated with Grafana. It is designed to be cost effective and easy to operate, as it does not index the contents of the logs, but rather a set of predefined labels for each log stream.
43+
44+
Grafana Loki is designed to be used in conjunction with metrics and tracing to provide a complete picture of an application's performance. Without the other two, it can be perceived as more cumbersome to use than a traditional logging system.
45+
46+
### Enabling Loki
47+
48+
Loki can be enabled by setting the list of logging destinations in your nais application manifest.
49+
50+
```yaml
51+
52+
spec:
53+
observability:
54+
logging:
55+
destinations:
56+
- id: loki
57+
```
58+
59+
## Elastic Kibana
60+
61+
Elasticsearch is a
62+
63+
### Configuring Kibana
64+
65+
66+
67+
### Working with Kibana
1068
1169
When you open Kibana you are prompted to select a workspace, select "Nav Logs" to start viewing your application logs.
1270
1371
Once the page loads you will see an empty page with a search bar. This is the query bar, and it is used to search for logs. You can use the query bar to search for logs by message, by field, or by a combination of both.
1472
15-
The query language is called [Kibana Query Language](https://www.elastic.co/guide/en/kibana/current/kuery-query.html) \(KQL\). KQL is a simplified version of Lucene query syntax. You can use KQL to search for logs by message, by field, or by a combination of both.
73+
The query language is called [Kibana Query Language](https://www.elastic.co/guide/en/kibana/current/kuery-query.html) (`KQL`). KQL is a simplified version of Lucene query syntax. You can use KQL to search for logs by message, by field, or by a combination of both.
1674

1775
There is also a time picker in the upper right corner of the page. You can use the time picker to select a time range to search for logs. The default time range is the last 15 minutes. If no logs shows up, try to increase the time range.
1876

@@ -42,8 +100,7 @@ The following fields are common to all logs and can be used in the query bar:
42100
| `message: "my message" AND level: "ERROR" AND NOT level: "WARN"` | Search for logs with the message "my message" and the level "ERROR" and not the level "WARN" |
43101
| `message: "my message" AND level: "ERROR" OR level: "WARN"` | Search for logs with the message "my message" and the level "ERROR" or the level "WARN" |
44102

45-
46-
## Gain access to logs.adeo.no
103+
### Gain access to Kibana
47104

48105
In order to get access to logs.adeo.no you need to have the correct access rights added to your AD account. This can be requested through your Personnal Manager.
49106

@@ -66,7 +123,7 @@ Secure logs can be enabled by setting the `secureLogs.enabled` flag in the appli
66123

67124
### Log files
68125

69-
With secure logs enabled a directory `/secure-logs/` will be mounted in the application container. Every `*.log` file in this directory will be monitored and the content transferred to Elasticsearch. Make sure that these files are readable for the log shipper \(the process runs as uid/gid 1065\).
126+
With secure logs enabled a directory `/secure-logs/` will be mounted in the application container. Every `*.log` file in this directory will be monitored and the content transferred to Elasticsearch. Make sure that these files are readable for the log shipper (`the process runs as uid/gid 1065`).
70127

71128
The `/secure-logs/` directory has a size limit of 128Mb, and it's the application responsibility to ensure that this limit is not exceeded. **If the limit is exceeded the application pod will be evicted and restarted.** Use log rotation on file size to avoid this.
72129

@@ -111,29 +168,20 @@ If you do not want to have these logs as files in the pod, it is also possible t
111168
curl -X POST -d '{"log":"hello world","field1":"value1"}' -H 'Content-Type: application/json' http://localhost:19880/
112169
```
113170

114-
## Audit logs
115-
116-
Most applications where a user processes data related to another user need to log audit statements, detailing which user did what action on which subject.
117-
These logs need to follow a specific format and be accessible by ArcSight.
118-
See [naudit](https://github.com/navikt/naudit) for how to set up the logging, and details on the log format.
119-
120-
## Overview
121-
122-
![The flow diagram shows that you can configure your app to log to a file using stdout or stderr, run FluentD inside the cluster to scrape the logs and send it to Elasticsearch. This will make the logs available via Kibana.](../../assets/logging_overview.png)
123-
124-
## Gaining access in kibana
171+
### Gain access to Secure Logs
125172

126173
Once everything is configured, your secure logs will be sent to the `tjenestekall-*` index in kibana. To gain access to these logs, you need to do the following:
127174

128-
### 1 Create an AD-group
175+
#### 1 Create an AD-group
129176

130177
To make sure you gain access to the proper logs, you need an AD-group connected to the nais-team. So the first thing you do is create this group.
131178

132179
Go to [Porten (service desk)](https://jira.adeo.no/plugins/servlet/desk/portal/542) and click `Melde sak til IT`. The follow the template below.
133180
For IT to be able to correctly add the group to Remedy you need to specify the four digit department code for those who can be able to ask for permission to the group. E.g 2990 is the four digit code for the department IT-AVDELINGEN. If you are creating secure logs for your team and are unsure about which department your colleagues belong to then you can use [Delve](https://eur.delve.office.com/) to search for their profile. In their profile their department code will also be visible.
134181

135182
You can paste the template below into Jira:
136-
```
183+
184+
```text
137185
Ønsker å få opprettet en AD-gruppe for å få tilgang til sikker logg i Kibana for applikasjoner knyttet til <your project here>.
138186
139187
Gruppenavn: 0000-GA-SECURE_LOG_<SOMETHING>
@@ -148,20 +196,26 @@ Enheter i Nav som skal ha tilgang: <four digit department code>. E.g (2990 - IT-
148196

149197
![ticket](../../assets/jira_secure_log.png)
150198

151-
### 2 Connect the AD group to your team in Kibana
199+
#### 2 Connect the AD group to your team in Kibana
152200

153201
The logs your apps produces are linked with your [nais-team](../../basics/teams.md).
154202
Administrators of Kibana will create a role for your team with read rights to those logs.
155203
Whoever is in the AD-group (created in step 1) will get the Kibana role, and can thus read all logs produced by apps belonging to the nais-team.
156204

157205
Ask in the [#atom](https://nav-it.slack.com/archives/C7TQ25L9J) Slack channel to connect the AD-group (created in step 1) to your nais-team.
158206

159-
### 3 Put people into the AD-group
207+
#### 3 Put people into the AD-group
160208

161209
This must be done by "identansvarlig". For NAV-IT employees, this is `[email protected]`. Send them an email and ask for access with a CC to whoever is your superior.
162210

163211
For everyone else, the team lead or who ever is their superior should know.
164212

165-
### What can go wrong?
213+
#### What can go wrong?
166214

167215
Basically, the one thing that can go wrong here is that the AD-group is not registered in "identrutinen". If this happens, the group cannot be found by "identansvarlig". If this happens, make a new JIRA-ticket to the same people and tell them to transfer the group. Sadly this can take a few days.
216+
217+
## Audit logs
218+
219+
Most applications where a user processes data related to another user need to log audit statements, detailing which user did what action on which subject.
220+
These logs need to follow a specific format and be accessible by ArcSight.
221+
See [naudit](https://github.com/navikt/naudit) for how to set up the logging, and details on the log format.

docs/observability/logs/elastic.md

Whitespace-only changes.

docs/observability/logs/loki.md

Whitespace-only changes.

docs/observability/logs/securelogs.md

Whitespace-only changes.

0 commit comments

Comments
 (0)