aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/main/java/com/yahoo/container/logging/ConnectionLogEntry.java
blob: 2f1dc1fd96fd9f5f1b59b45c0f70c34fa28bf57e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

package com.yahoo.container.logging;

import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
 * @author mortent
 */
public class ConnectionLogEntry {

    private final UUID id;
    private final Instant timestamp;
    private final Double durationSeconds;
    private final String peerAddress;
    private final Integer peerPort;
    private final String localAddress;
    private final Integer localPort;
    private final String remoteAddress;
    private final Integer remotePort;
    private final Long httpBytesReceived;
    private final Long httpBytesSent;
    private final Long requests;
    private final Long responses;
    private final String sslSessionId;
    private final String sslProtocol;
    private final String sslCipherSuite;
    private final String sslPeerSubject;
    private final Instant sslPeerNotBefore;
    private final Instant sslPeerNotAfter;
    private final String sslPeerIssuerSubject;
    private final String sslPeerFingerprint;
    private final String sslSniServerName;
    private final SslHandshakeFailure sslHandshakeFailure;
    private final List<String> sslSubjectAlternativeNames;
    private final String httpProtocol;
    private final String proxyProtocolVersion;
    private final Long sslBytesReceived;
    private final Long sslBytesSent;


    private ConnectionLogEntry(Builder builder) {
        this.id = builder.id;
        this.timestamp = builder.timestamp;
        this.durationSeconds = builder.durationSeconds;
        this.peerAddress = builder.peerAddress;
        this.peerPort = builder.peerPort;
        this.localAddress = builder.localAddress;
        this.localPort = builder.localPort;
        this.remoteAddress = builder.remoteAddress;
        this.remotePort = builder.remotePort;
        this.httpBytesReceived = builder.httpBytesReceived;
        this.httpBytesSent = builder.httpBytesSent;
        this.requests = builder.requests;
        this.responses = builder.responses;
        this.sslSessionId = builder.sslSessionId;
        this.sslProtocol = builder.sslProtocol;
        this.sslCipherSuite = builder.sslCipherSuite;
        this.sslPeerSubject = builder.sslPeerSubject;
        this.sslPeerNotBefore = builder.sslPeerNotBefore;
        this.sslPeerNotAfter = builder.sslPeerNotAfter;
        this.sslPeerIssuerSubject = builder.sslPeerIssuerSubject;
        this.sslPeerFingerprint = builder.sslPeerFingerprint;
        this.sslSniServerName = builder.sslSniServerName;
        this.sslHandshakeFailure = builder.sslHandshakeFailure;
        this.sslSubjectAlternativeNames = builder.sslSubjectAlternativeNames;
        this.httpProtocol = builder.httpProtocol;
        this.proxyProtocolVersion = builder.proxyProtocolVersion;
        this.sslBytesReceived = builder.sslBytesReceived;
        this.sslBytesSent = builder.sslBytesSent;
    }

    public static Builder builder(UUID id, Instant timestamp) {
        return new Builder(id, timestamp);
    }

    public String id() { return id.toString(); }
    public Instant timestamp() { return timestamp; }
    public Optional<Double> durationSeconds() { return Optional.ofNullable(durationSeconds); }
    public Optional<String> peerAddress() { return Optional.ofNullable(peerAddress); }
    public Optional<Integer> peerPort() { return Optional.ofNullable(peerPort); }
    public Optional<String> localAddress() { return Optional.ofNullable(localAddress); }
    public Optional<Integer> localPort() { return Optional.ofNullable(localPort); }
    public Optional<String> remoteAddress() { return Optional.ofNullable(remoteAddress); }
    public Optional<Integer> remotePort() { return Optional.ofNullable(remotePort); }
    public Optional<Long> httpBytesReceived() { return Optional.ofNullable(httpBytesReceived); }
    public Optional<Long> httpBytesSent() { return Optional.ofNullable(httpBytesSent); }
    public Optional<Long> requests() { return Optional.ofNullable(requests); }
    public Optional<Long> responses() { return Optional.ofNullable(responses); }
    public Optional<String> sslSessionId() { return Optional.ofNullable(sslSessionId); }
    public Optional<String> sslProtocol() { return Optional.ofNullable(sslProtocol); }
    public Optional<String> sslCipherSuite() { return Optional.ofNullable(sslCipherSuite); }
    public Optional<String> sslPeerSubject() { return Optional.ofNullable(sslPeerSubject); }
    public Optional<Instant> sslPeerNotBefore() { return Optional.ofNullable(sslPeerNotBefore); }
    public Optional<Instant> sslPeerNotAfter() { return Optional.ofNullable(sslPeerNotAfter); }
    public Optional<String> sslPeerIssuerSubject() { return Optional.ofNullable(sslPeerIssuerSubject); }
    public Optional<String> sslPeerFingerprint() { return Optional.ofNullable(sslPeerFingerprint); }
    public Optional<String> sslSniServerName() { return Optional.ofNullable(sslSniServerName); }
    public Optional<SslHandshakeFailure> sslHandshakeFailure() { return Optional.ofNullable(sslHandshakeFailure); }
    public List<String> sslSubjectAlternativeNames() { return sslSubjectAlternativeNames == null ? List.of() : sslSubjectAlternativeNames; }
    public Optional<String> httpProtocol() { return Optional.ofNullable(httpProtocol); }
    public Optional<String> proxyProtocolVersion() { return Optional.ofNullable(proxyProtocolVersion); }
    public Optional<Long> sslBytesReceived() { return Optional.ofNullable(sslBytesReceived); }
    public Optional<Long> sslBytesSent() { return Optional.ofNullable(sslBytesSent); }

    public static class SslHandshakeFailure {
        private final String type;
        private final List<ExceptionEntry> exceptionChain;

        public SslHandshakeFailure(String type, List<ExceptionEntry> exceptionChain) {
            this.type = type;
            this.exceptionChain = List.copyOf(exceptionChain);
        }

        public String type() { return type; }
        public List<ExceptionEntry> exceptionChain() { return exceptionChain; }

        public static class ExceptionEntry {
            private final String name;
            private final String message;

            public ExceptionEntry(String name, String message) {
                this.name = name;
                this.message = message;
            }

            public String name() { return name; }
            public String message() { return message; }
        }
    }

    public static class Builder {
        private final UUID id;
        private final Instant timestamp;
        private Double durationSeconds;
        private String peerAddress;
        private Integer peerPort;
        private String localAddress;
        private Integer localPort;
        private String remoteAddress;
        private Integer remotePort;
        private Long httpBytesReceived;
        private Long httpBytesSent;
        private Long requests;
        private Long responses;
        private String sslSessionId;
        private String sslProtocol;
        private String sslCipherSuite;
        private String sslPeerSubject;
        private Instant sslPeerNotBefore;
        private Instant sslPeerNotAfter;
        private String sslPeerIssuerSubject;
        private String sslPeerFingerprint;
        private String sslSniServerName;
        private SslHandshakeFailure sslHandshakeFailure;
        private List<String> sslSubjectAlternativeNames;
        private String httpProtocol;
        private String proxyProtocolVersion;
        private Long sslBytesReceived;
        private Long sslBytesSent;


        Builder(UUID id, Instant timestamp) {
            this.id = id;
            this.timestamp = timestamp;
        }

        public Builder withDuration(double durationSeconds) {
            this.durationSeconds = durationSeconds;
            return this;
        }

        public Builder withPeerAddress(String peerAddress) {
            this.peerAddress = peerAddress;
            return this;
        }
        public Builder withPeerPort(int peerPort) {
            this.peerPort = peerPort;
            return this;
        }
        public Builder withLocalAddress(String localAddress) {
            this.localAddress = localAddress;
            return this;
        }
        public Builder withLocalPort(int localPort) {
            this.localPort = localPort;
            return this;
        }
        public Builder withRemoteAddress(String remoteAddress) {
            this.remoteAddress = remoteAddress;
            return this;
        }
        public Builder withRemotePort(int remotePort) {
            this.remotePort = remotePort;
            return this;
        }
        public Builder withHttpBytesReceived(long bytesReceived) {
            this.httpBytesReceived = bytesReceived;
            return this;
        }
        public Builder withHttpBytesSent(long bytesSent) {
            this.httpBytesSent = bytesSent;
            return this;
        }
        public Builder withRequests(long requests) {
            this.requests = requests;
            return this;
        }
        public Builder withResponses(long responses) {
            this.responses = responses;
            return this;
        }
        public Builder withSslSessionId(String sslSessionId) {
            this.sslSessionId = sslSessionId;
            return this;
        }
        public Builder withSslProtocol(String sslProtocol) {
            this.sslProtocol = sslProtocol;
            return this;
        }
        public Builder withSslCipherSuite(String sslCipherSuite) {
            this.sslCipherSuite = sslCipherSuite;
            return this;
        }
        public Builder withSslPeerSubject(String sslPeerSubject) {
            this.sslPeerSubject = sslPeerSubject;
            return this;
        }
        public Builder withSslPeerNotBefore(Instant sslPeerNotBefore) {
            this.sslPeerNotBefore = sslPeerNotBefore;
            return this;
        }
        public Builder withSslPeerNotAfter(Instant sslPeerNotAfter) {
            this.sslPeerNotAfter = sslPeerNotAfter;
            return this;
        }
        public Builder withSslPeerIssuerSubject(String value) {
            this.sslPeerIssuerSubject = value;
            return this;
        }
        public Builder withSslPeerFingerprint(String value) {
            this.sslPeerFingerprint = value;
            return this;
        }
        public Builder withSslSniServerName(String sslSniServerName) {
            this.sslSniServerName = sslSniServerName;
            return this;
        }
        public Builder withSslHandshakeFailure(SslHandshakeFailure sslHandshakeFailure) {
            this.sslHandshakeFailure = sslHandshakeFailure;
            return this;
        }
        public Builder withSslSubjectAlternativeNames(List<String> sslSubjectAlternativeNames) {
            this.sslSubjectAlternativeNames = sslSubjectAlternativeNames;
            return this;
        }
        public Builder withHttpProtocol(String protocol) {
            this.httpProtocol = protocol;
            return this;
        }
        public Builder withProxyProtocolVersion(String version) {
            this.proxyProtocolVersion = version;
            return this;
        }
        public Builder withSslBytesReceived(long bytesReceived) {
            this.sslBytesReceived = bytesReceived;
            return this;
        }
        public Builder withSslBytesSent(long bytesSent) {
            this.sslBytesSent = bytesSent;
            return this;
        }

        public ConnectionLogEntry build(){
            return new ConnectionLogEntry(this);
        }

    }
}