This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: [skip ci] add logging & metrics scripts and config Signed-off-by: Lin Yang <reaver@flomesh.io> * wip: [skip ci] logging Signed-off-by: Lin Yang <reaver@flomesh.io> * wip: [skip ci] refactoring config change listeners Signed-off-by: Lin Yang <reaver@flomesh.io> * wip: [skip ci] add missing config Signed-off-by: Lin Yang <reaver@flomesh.io> * chore: initialize version v0.2.4-alpha.2 Signed-off-by: Lin Yang <reaver@flomesh.io> chore: initialize version v0.2.4-alpha.2 Signed-off-by: Lin Yang <reaver@flomesh.io> * feat: update logging config Signed-off-by: Lin Yang <reaver@flomesh.io> * chore: regenerate deploy yaml Signed-off-by: Lin Yang <reaver@flomesh.io> * fix: make package-scripts Signed-off-by: Lin Yang <reaver@flomesh.io> * fix: broken values Signed-off-by: Lin Yang <reaver@flomesh.io> * build: bump pipy to 0.90.0-185 Signed-off-by: Lin Yang <reaver@flomesh.io> * wip: [skip ci] update logging config Signed-off-by: Lin Yang <reaver@flomesh.io> * chore: regenerate deploy yaml Signed-off-by: Lin Yang <reaver@flomesh.io> * fix: make package-scripts Signed-off-by: Lin Yang <reaver@flomesh.io> * feat: implement logging & metrics scripts Signed-off-by: Lin Yang <reaver@flomesh.io> * fix: logging script Signed-off-by: Lin Yang <reaver@flomesh.io> * fix: logging script Signed-off-by: Lin Yang <reaver@flomesh.io> * fix: a typo in Helm chart Signed-off-by: Lin Yang <reaver@flomesh.io> --------- Signed-off-by: Lin Yang <reaver@flomesh.io>
- Loading branch information
1 parent
e6304e8
commit c4d1f1e
Showing
35 changed files
with
878 additions
and
356 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) since 2021, flomesh.io Authors. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
(( | ||
{config, logLogger} = pipy.solve('config.js'), | ||
) => pipy({ | ||
_reqHead: null, | ||
_reqBody: '', | ||
_reqTime: 0, | ||
_reqSize: 0, | ||
_resHead: null, | ||
_resTime: 0, | ||
_resSize: 0, | ||
_resBody: '', | ||
_instanceName: os.env.HOSTNAME, | ||
|
||
_CONTENT_TYPES: { | ||
'': true, | ||
'text/plain': true, | ||
'application/json': true, | ||
'application/xml': true, | ||
'multipart/form-data': true, | ||
}, | ||
}) | ||
|
||
.pipeline() | ||
.handleMessageStart( | ||
msg => ( | ||
_reqHead = msg.head, | ||
_reqBody = msg?.body?.toString?.() || '', | ||
_reqTime = Date.now() | ||
) | ||
) | ||
.handleData(data => _reqSize += data.size) | ||
.chain() | ||
.handleMessageStart( | ||
(msg, contentType) => ( | ||
_resHead = msg.head, | ||
_resTime = Date.now(), | ||
contentType = (msg.head.headers && msg.head.headers['content-type']) || '', | ||
_resBody = Boolean(_CONTENT_TYPES[contentType]) ? msg?.body?.toString?.() || '' : '' | ||
) | ||
) | ||
.handleData(data => _resSize += data.size) | ||
.handleMessageEnd( | ||
() => ( | ||
logLogger?.log({ | ||
req: { | ||
..._reqHead, | ||
body: _reqBody, | ||
}, | ||
res: { | ||
..._resHead, | ||
body: _resBody, | ||
}, | ||
x_parameters: { aid: '', igid: '', pid: '' }, | ||
instanceName: _instanceName, | ||
reqTime: _reqTime, | ||
resTime: _resTime, | ||
endTime: Date.now(), | ||
reqSize: _reqSize, | ||
resSize: _resSize, | ||
remoteAddr: __inbound?.remoteAddress, | ||
remotePort: __inbound?.remotePort, | ||
localAddr: __inbound?.localAddress, | ||
localPort: __inbound?.localPort, | ||
}) | ||
) | ||
) | ||
|
||
)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) since 2021, flomesh.io Authors. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
(( | ||
metricRequestCount = new stats.Counter('request_count', ["host", "path", "method"]), | ||
metricResponseStatus = new stats.Counter('response_status', ["host", "path", "method", "status"]), | ||
metricResponseLatency = new stats.Histogram( | ||
'request_latency', | ||
new Array(26).fill().map((_,i) => Math.pow(1.5, i+1)|0).concat([Infinity]), | ||
["host", "path", "method"], | ||
), | ||
) => pipy({ | ||
_requestTime: 0, | ||
_reqHead: null, | ||
}) | ||
|
||
.import({ | ||
__route: 'main', | ||
}) | ||
|
||
.pipeline() | ||
.handleMessageStart( | ||
(msg) => ( | ||
_reqHead = msg.head, | ||
_requestTime = Date.now(), | ||
metricRequestCount.withLabels(_reqHead.headers.host, _reqHead.path, _reqHead.method).increase() | ||
) | ||
) | ||
.chain() | ||
.handleMessageStart( | ||
msg => ( | ||
metricResponseLatency.withLabels(_reqHead.headers.host, _reqHead.path, _reqHead.method).observe(Date.now() - _requestTime), | ||
metricResponseStatus.withLabels(_reqHead.headers.host, _reqHead.path, _reqHead.method, msg.head.status || 200).increase() | ||
) | ||
) | ||
)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{- if .Values.fsm.logging.enabled }} | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
namespace: {{ include "fsm.namespace" . }} | ||
name: {{ .Values.fsm.logging.secretName }} | ||
type: Opaque | ||
data: | ||
url: {{ .Values.fsm.logging.url | b64enc }} | ||
token: {{ .Values.fsm.logging.token | b64enc }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) since 2021, flomesh.io Authors. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/flomesh-io/fsm/pkg/commons" | ||
"github.com/flomesh-io/fsm/pkg/config" | ||
"github.com/flomesh-io/fsm/pkg/config/utils" | ||
"github.com/flomesh-io/fsm/pkg/kube" | ||
"github.com/flomesh-io/fsm/pkg/repo" | ||
"os" | ||
) | ||
|
||
func setupLogging(api *kube.K8sAPI, repoClient *repo.PipyRepoClient, mc *config.MeshConfig) { | ||
if err := utils.UpdateLoggingConfig(api, commons.DefaultIngressBasePath, repoClient, mc); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.