mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-06 12:59:13 +00:00
Technical depth: Adding Go linter to CI (#734)
This commit is contained in:
parent
daf6b3db06
commit
0f6c56986f
@ -1,4 +1,4 @@
|
|||||||
name: PR validation
|
name: Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@ -12,7 +12,7 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-cli:
|
build-cli:
|
||||||
name: Build CLI executable
|
name: CLI executable build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go 1.16
|
- name: Set up Go 1.16
|
||||||
@ -27,7 +27,7 @@ jobs:
|
|||||||
run: make cli
|
run: make cli
|
||||||
|
|
||||||
build-agent:
|
build-agent:
|
||||||
name: Build Agent docker image
|
name: Agent docker image build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
50
.github/workflows/static_code_analysis.yml
vendored
Normal file
50
.github/workflows/static_code_analysis.yml
vendored
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
name: Static code analysis
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'develop'
|
||||||
|
- 'main'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
golangci:
|
||||||
|
name: Go lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y libpcap-dev
|
||||||
|
|
||||||
|
- name: Go lint - agent
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
working-directory: agent
|
||||||
|
args: --timeout=3m
|
||||||
|
|
||||||
|
- name: Go lint - shared
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
working-directory: shared
|
||||||
|
args: --timeout=3m
|
||||||
|
|
||||||
|
- name: Go lint - tap
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
working-directory: tap
|
||||||
|
args: --timeout=3m
|
||||||
|
|
||||||
|
- name: Go lint - CLI
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
working-directory: cli
|
||||||
|
args: --timeout=3m
|
@ -1,14 +1,10 @@
|
|||||||
name: tests validation
|
name: Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- 'develop'
|
- 'develop'
|
||||||
- 'main'
|
- 'main'
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- 'develop'
|
|
||||||
- 'main'
|
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: mizu-tests-validation-${{ github.ref }}
|
group: mizu-tests-validation-${{ github.ref }}
|
||||||
@ -16,7 +12,7 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-tests-cli:
|
run-tests-cli:
|
||||||
name: Run CLI tests
|
name: CLI Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go 1.16
|
- name: Set up Go 1.16
|
||||||
@ -34,7 +30,7 @@ jobs:
|
|||||||
uses: codecov/codecov-action@v2
|
uses: codecov/codecov-action@v2
|
||||||
|
|
||||||
run-tests-agent:
|
run-tests-agent:
|
||||||
name: Run Agent tests
|
name: Agent Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go 1.16
|
- name: Set up Go 1.16
|
@ -42,10 +42,8 @@ func StartResolving(namespace string) {
|
|||||||
res.Start(ctx)
|
res.Start(ctx)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
err := <-errOut
|
||||||
case err := <-errOut:
|
logger.Log.Infof("name resolving error %s", err)
|
||||||
logger.Log.Infof("name resolving error %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -67,7 +65,7 @@ func startReadingFiles(workingDir string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for true {
|
for {
|
||||||
dir, _ := os.Open(workingDir)
|
dir, _ := os.Open(workingDir)
|
||||||
dirFiles, _ := dir.Readdir(-1)
|
dirFiles, _ := dir.Readdir(-1)
|
||||||
|
|
||||||
@ -124,7 +122,9 @@ func startReadingChannel(outputItems <-chan *tapApi.OutputChannelItem, extension
|
|||||||
if extension.Protocol.Name == "http" {
|
if extension.Protocol.Name == "http" {
|
||||||
if !disableOASValidation {
|
if !disableOASValidation {
|
||||||
var httpPair tapApi.HTTPRequestResponsePair
|
var httpPair tapApi.HTTPRequestResponsePair
|
||||||
json.Unmarshal([]byte(mizuEntry.HTTPPair), &httpPair)
|
if err := json.Unmarshal([]byte(mizuEntry.HTTPPair), &httpPair); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
contract := handleOAS(ctx, doc, router, httpPair.Request.Payload.RawRequest, httpPair.Response.Payload.RawResponse, contractContent)
|
contract := handleOAS(ctx, doc, router, httpPair.Request.Payload.RawRequest, httpPair.Response.Payload.RawResponse, contractContent)
|
||||||
mizuEntry.ContractStatus = contract.Status
|
mizuEntry.ContractStatus = contract.Status
|
||||||
|
@ -2,7 +2,6 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"mizuserver/pkg/models"
|
"mizuserver/pkg/models"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -13,7 +12,6 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
basenine "github.com/up9inc/basenine/client/go"
|
basenine "github.com/up9inc/basenine/client/go"
|
||||||
"github.com/up9inc/mizu/shared"
|
"github.com/up9inc/mizu/shared"
|
||||||
"github.com/up9inc/mizu/shared/debounce"
|
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
tapApi "github.com/up9inc/mizu/tap/api"
|
tapApi "github.com/up9inc/mizu/tap/api"
|
||||||
)
|
)
|
||||||
@ -94,7 +92,10 @@ func websocketHandler(w http.ResponseWriter, r *http.Request, eventHandlers Even
|
|||||||
eventHandlers.WebSocketConnect(socketId, isTapper)
|
eventHandlers.WebSocketConnect(socketId, isTapper)
|
||||||
|
|
||||||
startTimeBytes, _ := models.CreateWebsocketStartTimeMessage(startTime)
|
startTimeBytes, _ := models.CreateWebsocketStartTimeMessage(startTime)
|
||||||
SendToSocket(socketId, startTimeBytes)
|
|
||||||
|
if err = SendToSocket(socketId, startTimeBytes); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
_, msg, err := ws.ReadMessage()
|
_, msg, err := ws.ReadMessage()
|
||||||
@ -117,7 +118,9 @@ func websocketHandler(w http.ResponseWriter, r *http.Request, eventHandlers Even
|
|||||||
AutoClose: 5000,
|
AutoClose: 5000,
|
||||||
Text: fmt.Sprintf("Syntax error: %s", err.Error()),
|
Text: fmt.Sprintf("Syntax error: %s", err.Error()),
|
||||||
})
|
})
|
||||||
SendToSocket(socketId, toastBytes)
|
if err := SendToSocket(socketId, toastBytes); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +140,9 @@ func websocketHandler(w http.ResponseWriter, r *http.Request, eventHandlers Even
|
|||||||
base := tapApi.Summarize(entry)
|
base := tapApi.Summarize(entry)
|
||||||
|
|
||||||
baseEntryBytes, _ := models.CreateBaseEntryWebSocketMessage(base)
|
baseEntryBytes, _ := models.CreateBaseEntryWebSocketMessage(base)
|
||||||
SendToSocket(socketId, baseEntryBytes)
|
if err := SendToSocket(socketId, baseEntryBytes); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +161,9 @@ func websocketHandler(w http.ResponseWriter, r *http.Request, eventHandlers Even
|
|||||||
}
|
}
|
||||||
|
|
||||||
metadataBytes, _ := models.CreateWebsocketQueryMetadataMessage(metadata)
|
metadataBytes, _ := models.CreateWebsocketQueryMetadataMessage(metadata)
|
||||||
SendToSocket(socketId, metadataBytes)
|
if err := SendToSocket(socketId, metadataBytes); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,14 +190,10 @@ func socketCleanup(socketId int, socketConnection *SocketConnection) {
|
|||||||
socketConnection.eventHandlers.WebSocketDisconnect(socketId, socketConnection.isTapper)
|
socketConnection.eventHandlers.WebSocketDisconnect(socketId, socketConnection.isTapper)
|
||||||
}
|
}
|
||||||
|
|
||||||
var db = debounce.NewDebouncer(time.Second*5, func() {
|
|
||||||
logger.Log.Error("Successfully sent to socket")
|
|
||||||
})
|
|
||||||
|
|
||||||
func SendToSocket(socketId int, message []byte) error {
|
func SendToSocket(socketId int, message []byte) error {
|
||||||
socketObj := connectedWebsockets[socketId]
|
socketObj := connectedWebsockets[socketId]
|
||||||
if socketObj == nil {
|
if socketObj == nil {
|
||||||
return errors.New("Socket is disconnected")
|
return fmt.Errorf("Socket %v is disconnected", socketId)
|
||||||
}
|
}
|
||||||
|
|
||||||
var sent = false
|
var sent = false
|
||||||
@ -204,7 +207,10 @@ func SendToSocket(socketId int, message []byte) error {
|
|||||||
socketObj.lock.Lock() // gorilla socket panics from concurrent writes to a single socket
|
socketObj.lock.Lock() // gorilla socket panics from concurrent writes to a single socket
|
||||||
err := socketObj.connection.WriteMessage(1, message)
|
err := socketObj.connection.WriteMessage(1, message)
|
||||||
socketObj.lock.Unlock()
|
socketObj.lock.Unlock()
|
||||||
|
|
||||||
sent = true
|
sent = true
|
||||||
return err
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to write message to socket %v, err: %w", socketId, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -54,9 +54,8 @@ func (h *RoutesEventHandlers) WebSocketDisconnect(socketId int, isTapper bool) {
|
|||||||
func BroadcastToBrowserClients(message []byte) {
|
func BroadcastToBrowserClients(message []byte) {
|
||||||
for _, socketId := range browserClientSocketUUIDs {
|
for _, socketId := range browserClientSocketUUIDs {
|
||||||
go func(socketId int) {
|
go func(socketId int) {
|
||||||
err := SendToSocket(socketId, message)
|
if err := SendToSocket(socketId, message); err != nil {
|
||||||
if err != nil {
|
logger.Log.Error(err)
|
||||||
logger.Log.Errorf("error sending message to socket ID %d: %v", socketId, err)
|
|
||||||
}
|
}
|
||||||
}(socketId)
|
}(socketId)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ func InitExtensionsMap(ref map[string]*tapApi.Extension) {
|
|||||||
func Error(c *gin.Context, err error) bool {
|
func Error(c *gin.Context, err error) bool {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log.Errorf("Error getting entry: %v", err)
|
logger.Log.Errorf("Error getting entry: %v", err)
|
||||||
c.Error(err)
|
_ = c.Error(err)
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": true,
|
"error": true,
|
||||||
"type": "error",
|
"type": "error",
|
||||||
@ -131,7 +131,9 @@ func GetEntry(c *gin.Context) {
|
|||||||
_, rulesMatched, _isRulesEnabled := models.RunValidationRulesState(*harEntry, entry.Destination.Name)
|
_, rulesMatched, _isRulesEnabled := models.RunValidationRulesState(*harEntry, entry.Destination.Name)
|
||||||
isRulesEnabled = _isRulesEnabled
|
isRulesEnabled = _isRulesEnabled
|
||||||
inrec, _ := json.Marshal(rulesMatched)
|
inrec, _ := json.Marshal(rulesMatched)
|
||||||
json.Unmarshal(inrec, &rules)
|
if err := json.Unmarshal(inrec, &rules); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, tapApi.EntryWrapper{
|
c.JSON(http.StatusOK, tapApi.EntryWrapper{
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"mizuserver/pkg/oas"
|
"mizuserver/pkg/oas"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetOASServers(t *testing.T) {
|
func TestGetOASServers(t *testing.T) {
|
||||||
@ -15,7 +16,6 @@ func TestGetOASServers(t *testing.T) {
|
|||||||
|
|
||||||
GetOASServers(c)
|
GetOASServers(c)
|
||||||
t.Logf("Written body: %s", recorder.Body.String())
|
t.Logf("Written body: %s", recorder.Body.String())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetOASAllSpecs(t *testing.T) {
|
func TestGetOASAllSpecs(t *testing.T) {
|
||||||
@ -26,7 +26,6 @@ func TestGetOASAllSpecs(t *testing.T) {
|
|||||||
|
|
||||||
GetOASAllSpecs(c)
|
GetOASAllSpecs(c)
|
||||||
t.Logf("Written body: %s", recorder.Body.String())
|
t.Logf("Written body: %s", recorder.Body.String())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetOASSpec(t *testing.T) {
|
func TestGetOASSpec(t *testing.T) {
|
||||||
@ -39,5 +38,4 @@ func TestGetOASSpec(t *testing.T) {
|
|||||||
|
|
||||||
GetOASSpec(c)
|
GetOASSpec(c)
|
||||||
t.Logf("Written body: %s", recorder.Body.String())
|
t.Logf("Written body: %s", recorder.Body.String())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -123,11 +123,11 @@ func NewRequest(request map[string]interface{}) (harRequest *Request, err error)
|
|||||||
cookies := make([]Cookie, 0) // BuildCookies(request["_cookies"].([]interface{}))
|
cookies := make([]Cookie, 0) // BuildCookies(request["_cookies"].([]interface{}))
|
||||||
|
|
||||||
postData, _ := request["postData"].(map[string]interface{})
|
postData, _ := request["postData"].(map[string]interface{})
|
||||||
mimeType, _ := postData["mimeType"]
|
mimeType := postData["mimeType"]
|
||||||
if mimeType == nil || len(mimeType.(string)) == 0 {
|
if mimeType == nil || len(mimeType.(string)) == 0 {
|
||||||
mimeType = "text/html"
|
mimeType = "text/html"
|
||||||
}
|
}
|
||||||
text, _ := postData["text"]
|
text := postData["text"]
|
||||||
postDataText := ""
|
postDataText := ""
|
||||||
if text != nil {
|
if text != nil {
|
||||||
postDataText = text.(string)
|
postDataText = text.(string)
|
||||||
@ -176,12 +176,12 @@ func NewResponse(response map[string]interface{}) (harResponse *Response, err er
|
|||||||
cookies := make([]Cookie, 0) // BuildCookies(response["_cookies"].([]interface{}))
|
cookies := make([]Cookie, 0) // BuildCookies(response["_cookies"].([]interface{}))
|
||||||
|
|
||||||
content, _ := response["content"].(map[string]interface{})
|
content, _ := response["content"].(map[string]interface{})
|
||||||
mimeType, _ := content["mimeType"]
|
mimeType := content["mimeType"]
|
||||||
if mimeType == nil || len(mimeType.(string)) == 0 {
|
if mimeType == nil || len(mimeType.(string)) == 0 {
|
||||||
mimeType = "text/html"
|
mimeType = "text/html"
|
||||||
}
|
}
|
||||||
encoding, _ := content["encoding"]
|
encoding := content["encoding"]
|
||||||
text, _ := content["text"]
|
text := content["text"]
|
||||||
bodyText := ""
|
bodyText := ""
|
||||||
if text != nil {
|
if text != nil {
|
||||||
bodyText = text.(string)
|
bodyText = text.(string)
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"mizuserver/pkg/har"
|
"mizuserver/pkg/har"
|
||||||
@ -13,10 +12,12 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getFiles(baseDir string) (result []string, err error) {
|
func getFiles(baseDir string) (result []string, err error) {
|
||||||
result = make([]string, 0, 0)
|
result = make([]string, 0)
|
||||||
logger.Log.Infof("Reading files from tree: %s", baseDir)
|
logger.Log.Infof("Reading files from tree: %s", baseDir)
|
||||||
|
|
||||||
// https://yourbasic.org/golang/list-files-in-directory/
|
// https://yourbasic.org/golang/list-files-in-directory/
|
||||||
@ -121,8 +122,6 @@ func feedEntry(entry *har.Entry, isSync bool) {
|
|||||||
|
|
||||||
if strings.Contains(entry.Request.URL, "taboola") {
|
if strings.Contains(entry.Request.URL, "taboola") {
|
||||||
logger.Log.Debugf("Interesting: %s", entry.Request.URL)
|
logger.Log.Debugf("Interesting: %s", entry.Request.URL)
|
||||||
} else {
|
|
||||||
//return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if isSync {
|
if isSync {
|
||||||
|
@ -33,11 +33,7 @@ func IsGibberish(str string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
noise := noiseLevel(str)
|
noise := noiseLevel(str)
|
||||||
if noise >= 0.2 {
|
return noise >= 0.2
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func noiseLevel(str string) (score float64) {
|
func noiseLevel(str string) (score float64) {
|
||||||
|
@ -3,15 +3,16 @@ package oas
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/chanced/openapi"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
|
||||||
"mime"
|
"mime"
|
||||||
"mizuserver/pkg/har"
|
"mizuserver/pkg/har"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/chanced/openapi"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type reqResp struct { // hello, generics in Go
|
type reqResp struct { // hello, generics in Go
|
||||||
@ -272,7 +273,7 @@ func handleRequest(req *har.Request, opObj *openapi.Operation, isSuccess bool) e
|
|||||||
|
|
||||||
if reqBody != nil {
|
if reqBody != nil {
|
||||||
reqCtype := getReqCtype(req)
|
reqCtype := getReqCtype(req)
|
||||||
reqMedia, err := fillContent(reqResp{Req: req}, reqBody.Content, reqCtype, err)
|
reqMedia, err := fillContent(reqResp{Req: req}, reqBody.Content, reqCtype)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -294,7 +295,7 @@ func handleResponse(resp *har.Response, opObj *openapi.Operation, isSuccess bool
|
|||||||
|
|
||||||
respCtype := getRespCtype(resp)
|
respCtype := getRespCtype(resp)
|
||||||
respContent := respObj.Content
|
respContent := respObj.Content
|
||||||
respMedia, err := fillContent(reqResp{Resp: resp}, respContent, respCtype, err)
|
respMedia, err := fillContent(reqResp{Resp: resp}, respContent, respCtype)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -342,11 +343,9 @@ func handleRespHeaders(reqHeaders []har.Header, respObj *openapi.ResponseObj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillContent(reqResp reqResp, respContent openapi.Content, ctype string, err error) (*openapi.MediaType, error) {
|
func fillContent(reqResp reqResp, respContent openapi.Content, ctype string) (*openapi.MediaType, error) {
|
||||||
content, found := respContent[ctype]
|
content, found := respContent[ctype]
|
||||||
if !found {
|
if !found {
|
||||||
respContent[ctype] = &openapi.MediaType{}
|
respContent[ctype] = &openapi.MediaType{}
|
||||||
@ -367,14 +366,16 @@ func fillContent(reqResp reqResp, respContent openapi.Content, ctype string, err
|
|||||||
any, isJSON := anyJSON(text)
|
any, isJSON := anyJSON(text)
|
||||||
if isJSON {
|
if isJSON {
|
||||||
// re-marshal with forced indent
|
// re-marshal with forced indent
|
||||||
exampleMsg, err = json.MarshalIndent(any, "", "\t")
|
if msg, err := json.MarshalIndent(any, "", "\t"); err != nil {
|
||||||
if err != nil {
|
|
||||||
panic("Failed to re-marshal value, super-strange")
|
panic("Failed to re-marshal value, super-strange")
|
||||||
|
} else {
|
||||||
|
exampleMsg = msg
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
exampleMsg, err = json.Marshal(text)
|
if msg, err := json.Marshal(text); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else {
|
||||||
|
exampleMsg = msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,8 +171,6 @@ func loadStartingOAS() {
|
|||||||
gen.StartFromSpec(doc)
|
gen.StartFromSpec(doc)
|
||||||
|
|
||||||
GetOasGeneratorInstance().ServiceSpecs.Store("catalogue", gen)
|
GetOasGeneratorInstance().ServiceSpecs.Store("catalogue", gen)
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEntriesNegative(t *testing.T) {
|
func TestEntriesNegative(t *testing.T) {
|
||||||
@ -224,5 +222,4 @@ func TestLoadValid3_1(t *testing.T) {
|
|||||||
t.Log(err)
|
t.Log(err)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package oas
|
package oas
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/chanced/openapi"
|
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/chanced/openapi"
|
||||||
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodePath = []string
|
type NodePath = []string
|
||||||
@ -162,9 +163,7 @@ func (n *Node) listPaths() *openapi.Paths {
|
|||||||
strChunk = *n.constant
|
strChunk = *n.constant
|
||||||
} else if n.pathParam != nil {
|
} else if n.pathParam != nil {
|
||||||
strChunk = "{" + n.pathParam.Name + "}"
|
strChunk = "{" + n.pathParam.Name + "}"
|
||||||
} else {
|
} // else -> this is the root node
|
||||||
// this is the root node
|
|
||||||
}
|
|
||||||
|
|
||||||
// add self
|
// add self
|
||||||
if n.pathObj != nil {
|
if n.pathObj != nil {
|
||||||
|
@ -3,11 +3,12 @@ package oas
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/chanced/openapi"
|
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
|
||||||
"mizuserver/pkg/har"
|
"mizuserver/pkg/har"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/chanced/openapi"
|
||||||
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
func exampleResolver(ref string) (*openapi.ExampleObj, error) {
|
func exampleResolver(ref string) (*openapi.ExampleObj, error) {
|
||||||
@ -32,16 +33,14 @@ func headerResolver(ref string) (*openapi.HeaderObj, error) {
|
|||||||
|
|
||||||
func initParams(obj **openapi.ParameterList) {
|
func initParams(obj **openapi.ParameterList) {
|
||||||
if *obj == nil {
|
if *obj == nil {
|
||||||
var params openapi.ParameterList
|
var params openapi.ParameterList = make([]openapi.Parameter, 0)
|
||||||
params = make([]openapi.Parameter, 0)
|
|
||||||
*obj = ¶ms
|
*obj = ¶ms
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initHeaders(respObj *openapi.ResponseObj) {
|
func initHeaders(respObj *openapi.ResponseObj) {
|
||||||
if respObj.Headers == nil {
|
if respObj.Headers == nil {
|
||||||
var created openapi.Headers
|
var created openapi.Headers = map[string]openapi.Header{}
|
||||||
created = map[string]openapi.Header{}
|
|
||||||
respObj.Headers = created
|
respObj.Headers = created
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,7 +84,7 @@ func findParamByName(params *openapi.ParameterList, in openapi.In, name string)
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if paramObj.Name == name || (caseInsensitive && strings.ToLower(paramObj.Name) == strings.ToLower(name)) {
|
if paramObj.Name == name || (caseInsensitive && strings.EqualFold(paramObj.Name, name)) {
|
||||||
pathParam = paramObj
|
pathParam = paramObj
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -102,7 +101,7 @@ func findHeaderByName(headers *openapi.Headers, name string) *openapi.HeaderObj
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ToLower(hname) == strings.ToLower(name) {
|
if strings.EqualFold(hname, name) {
|
||||||
return hdrObj
|
return hdrObj
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"mizuserver/pkg/config"
|
"mizuserver/pkg/config"
|
||||||
|
|
||||||
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
|
|
||||||
ory "github.com/ory/kratos-client-go"
|
ory "github.com/ory/kratos-client-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,7 +40,9 @@ func CreateAdminUser(password string, ctx context.Context) (token *string, err e
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//Delete the user to prevent a half-setup situation where admin user is created without admin privileges
|
//Delete the user to prevent a half-setup situation where admin user is created without admin privileges
|
||||||
DeleteUser(identityId, ctx)
|
if err := DeleteUser(identityId, ctx); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil, err, nil
|
return nil, err, nil
|
||||||
}
|
}
|
||||||
|
@ -85,11 +85,11 @@ func DeleteUser(identityId string, ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if result == nil {
|
if result == nil {
|
||||||
return errors.New("unknown error occured during user deletion")
|
return fmt.Errorf("unknown error occured during user deletion %v", identityId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result.StatusCode < 200 || result.StatusCode > 299 {
|
if result.StatusCode < 200 || result.StatusCode > 299 {
|
||||||
return errors.New(fmt.Sprintf("user deletion returned bad status %d", result.StatusCode))
|
return fmt.Errorf("user deletion %v returned bad status %d", identityId, result.StatusCode)
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func PassedValidationRules(rulesMatched []RulesMatched) (bool, int64, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, rule := range rulesMatched {
|
for _, rule := range rulesMatched {
|
||||||
if rule.Matched == false {
|
if !rule.Matched {
|
||||||
return false, responseTime, numberOfRulesMatched
|
return false, responseTime, numberOfRulesMatched
|
||||||
} else {
|
} else {
|
||||||
if strings.ToLower(rule.Rule.Type) == "slo" {
|
if strings.ToLower(rule.Rule.Type) == "slo" {
|
||||||
|
@ -31,9 +31,9 @@ func StartServer(app *gin.Engine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
_ = <-signals
|
<-signals
|
||||||
logger.Log.Infof("Shutting down...")
|
logger.Log.Infof("Shutting down...")
|
||||||
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) //nolint
|
||||||
_ = srv.Shutdown(ctx)
|
_ = srv.Shutdown(ctx)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
@ -91,7 +91,7 @@ func UniqueStringSlice(s []string) []string {
|
|||||||
uniqueMap := map[string]bool{}
|
uniqueMap := map[string]bool{}
|
||||||
|
|
||||||
for _, val := range s {
|
for _, val := range s {
|
||||||
if uniqueMap[val] == true {
|
if uniqueMap[val] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
uniqueMap[val] = true
|
uniqueMap[val] = true
|
||||||
|
@ -50,7 +50,9 @@ func init() {
|
|||||||
rootCmd.AddCommand(configCmd)
|
rootCmd.AddCommand(configCmd)
|
||||||
|
|
||||||
defaultConfig := config.ConfigStruct{}
|
defaultConfig := config.ConfigStruct{}
|
||||||
defaults.Set(&defaultConfig)
|
if err := defaults.Set(&defaultConfig); err != nil {
|
||||||
|
logger.Log.Debug(err)
|
||||||
|
}
|
||||||
|
|
||||||
configCmd.Flags().BoolP(configStructs.RegenerateConfigName, "r", defaultConfig.Config.Regenerate, fmt.Sprintf("Regenerate the config file with default values to path %s or to chosen path using --%s", defaultConfig.ConfigFilePath, config.ConfigFilePathCommandName))
|
configCmd.Flags().BoolP(configStructs.RegenerateConfigName, "r", defaultConfig.Config.Regenerate, fmt.Sprintf("Regenerate the config file with default values to path %s or to chosen path using --%s", defaultConfig.ConfigFilePath, config.ConfigFilePathCommandName))
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,9 @@ func runMizuInstall() {
|
|||||||
var defaultMaxEntriesDBSizeBytes int64 = 200 * 1000 * 1000
|
var defaultMaxEntriesDBSizeBytes int64 = 200 * 1000 * 1000
|
||||||
|
|
||||||
defaultResources := shared.Resources{}
|
defaultResources := shared.Resources{}
|
||||||
defaults.Set(&defaultResources)
|
if err := defaults.Set(&defaultResources); err != nil {
|
||||||
|
logger.Log.Debug(err)
|
||||||
|
}
|
||||||
|
|
||||||
mizuAgentConfig := getInstallMizuAgentConfig(defaultMaxEntriesDBSizeBytes, defaultResources)
|
mizuAgentConfig := getInstallMizuAgentConfig(defaultMaxEntriesDBSizeBytes, defaultResources)
|
||||||
serializedMizuConfig, err := getSerializedMizuAgentConfig(mizuAgentConfig)
|
serializedMizuConfig, err := getSerializedMizuAgentConfig(mizuAgentConfig)
|
||||||
|
@ -43,7 +43,9 @@ func init() {
|
|||||||
rootCmd.AddCommand(logsCmd)
|
rootCmd.AddCommand(logsCmd)
|
||||||
|
|
||||||
defaultLogsConfig := configStructs.LogsConfig{}
|
defaultLogsConfig := configStructs.LogsConfig{}
|
||||||
defaults.Set(&defaultLogsConfig)
|
if err := defaults.Set(&defaultLogsConfig); err != nil {
|
||||||
|
logger.Log.Debug(err)
|
||||||
|
}
|
||||||
|
|
||||||
logsCmd.Flags().StringP(configStructs.FileLogsName, "f", defaultLogsConfig.FileStr, "Path for zip file (default current <pwd>\\mizu_logs.zip)")
|
logsCmd.Flags().StringP(configStructs.FileLogsName, "f", defaultLogsConfig.FileStr, "Path for zip file (default current <pwd>\\mizu_logs.zip)")
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,9 @@ Further info is available at https://github.com/up9inc/mizu`,
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
defaultConfig := config.ConfigStruct{}
|
defaultConfig := config.ConfigStruct{}
|
||||||
defaults.Set(&defaultConfig)
|
if err := defaults.Set(&defaultConfig); err != nil {
|
||||||
|
logger.Log.Debug(err)
|
||||||
|
}
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringSlice(config.SetCommandName, []string{}, fmt.Sprintf("Override values using --%s", config.SetCommandName))
|
rootCmd.PersistentFlags().StringSlice(config.SetCommandName, []string{}, fmt.Sprintf("Override values using --%s", config.SetCommandName))
|
||||||
rootCmd.PersistentFlags().String(config.ConfigFilePathCommandName, defaultConfig.ConfigFilePath, fmt.Sprintf("Override config file path using --%s", config.ConfigFilePathCommandName))
|
rootCmd.PersistentFlags().String(config.ConfigFilePathCommandName, defaultConfig.ConfigFilePath, fmt.Sprintf("Override config file path using --%s", config.ConfigFilePathCommandName))
|
||||||
|
@ -104,7 +104,9 @@ func init() {
|
|||||||
rootCmd.AddCommand(tapCmd)
|
rootCmd.AddCommand(tapCmd)
|
||||||
|
|
||||||
defaultTapConfig := configStructs.TapConfig{}
|
defaultTapConfig := configStructs.TapConfig{}
|
||||||
defaults.Set(&defaultTapConfig)
|
if err := defaults.Set(&defaultTapConfig); err != nil {
|
||||||
|
logger.Log.Debug(err)
|
||||||
|
}
|
||||||
|
|
||||||
tapCmd.Flags().Uint16P(configStructs.GuiPortTapName, "p", defaultTapConfig.GuiPort, "Provide a custom port for the web interface webserver")
|
tapCmd.Flags().Uint16P(configStructs.GuiPortTapName, "p", defaultTapConfig.GuiPort, "Provide a custom port for the web interface webserver")
|
||||||
tapCmd.Flags().StringSliceP(configStructs.NamespacesTapName, "n", defaultTapConfig.Namespaces, "Namespaces selector")
|
tapCmd.Flags().StringSliceP(configStructs.NamespacesTapName, "n", defaultTapConfig.Namespaces, "Namespaces selector")
|
||||||
|
@ -36,7 +36,9 @@ func init() {
|
|||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
|
||||||
defaultVersionConfig := configStructs.VersionConfig{}
|
defaultVersionConfig := configStructs.VersionConfig{}
|
||||||
defaults.Set(&defaultVersionConfig)
|
if err := defaults.Set(&defaultVersionConfig); err != nil {
|
||||||
|
logger.Log.Debug(err)
|
||||||
|
}
|
||||||
|
|
||||||
versionCmd.Flags().BoolP(configStructs.DebugInfoVersionName, "d", defaultVersionConfig.DebugInfo, "Provide all information about version")
|
versionCmd.Flags().BoolP(configStructs.DebugInfoVersionName, "d", defaultVersionConfig.DebugInfo, "Provide all information about version")
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/up9inc/mizu/cli/config"
|
"github.com/up9inc/mizu/cli/config"
|
||||||
"github.com/up9inc/mizu/cli/config/configStructs"
|
"github.com/up9inc/mizu/cli/config/configStructs"
|
||||||
"github.com/up9inc/mizu/cli/telemetry"
|
"github.com/up9inc/mizu/cli/telemetry"
|
||||||
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
var viewCmd = &cobra.Command{
|
var viewCmd = &cobra.Command{
|
||||||
@ -22,10 +23,14 @@ func init() {
|
|||||||
rootCmd.AddCommand(viewCmd)
|
rootCmd.AddCommand(viewCmd)
|
||||||
|
|
||||||
defaultViewConfig := configStructs.ViewConfig{}
|
defaultViewConfig := configStructs.ViewConfig{}
|
||||||
defaults.Set(&defaultViewConfig)
|
if err := defaults.Set(&defaultViewConfig); err != nil {
|
||||||
|
logger.Log.Debug(err)
|
||||||
|
}
|
||||||
|
|
||||||
viewCmd.Flags().Uint16P(configStructs.GuiPortViewName, "p", defaultViewConfig.GuiPort, "Provide a custom port for the web interface webserver")
|
viewCmd.Flags().Uint16P(configStructs.GuiPortViewName, "p", defaultViewConfig.GuiPort, "Provide a custom port for the web interface webserver")
|
||||||
viewCmd.Flags().StringP(configStructs.UrlViewName, "u", defaultViewConfig.Url, "Provide a custom host")
|
viewCmd.Flags().StringP(configStructs.UrlViewName, "u", defaultViewConfig.Url, "Provide a custom host")
|
||||||
|
|
||||||
viewCmd.Flags().MarkHidden(configStructs.UrlViewName)
|
if err := viewCmd.Flags().MarkHidden(configStructs.UrlViewName); err != nil {
|
||||||
|
logger.Log.Debug(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,12 +60,12 @@ func (config *TapConfig) MaxEntriesDBSizeBytes() int64 {
|
|||||||
func (config *TapConfig) Validate() error {
|
func (config *TapConfig) Validate() error {
|
||||||
_, compileErr := regexp.Compile(config.PodRegexStr)
|
_, compileErr := regexp.Compile(config.PodRegexStr)
|
||||||
if compileErr != nil {
|
if compileErr != nil {
|
||||||
return errors.New(fmt.Sprintf("%s is not a valid regex %s", config.PodRegexStr, compileErr))
|
return fmt.Errorf("%s is not a valid regex %s", config.PodRegexStr, compileErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, parseHumanDataSizeErr := units.HumanReadableToBytes(config.HumanMaxEntriesDBSize)
|
_, parseHumanDataSizeErr := units.HumanReadableToBytes(config.HumanMaxEntriesDBSize)
|
||||||
if parseHumanDataSizeErr != nil {
|
if parseHumanDataSizeErr != nil {
|
||||||
return errors.New(fmt.Sprintf("Could not parse --%s value %s", HumanMaxEntriesDBSizeTapName, config.HumanMaxEntriesDBSize))
|
return fmt.Errorf("Could not parse --%s value %s", HumanMaxEntriesDBSizeTapName, config.HumanMaxEntriesDBSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Workspace != "" {
|
if config.Workspace != "" {
|
||||||
@ -76,7 +76,7 @@ func (config *TapConfig) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.Analysis && config.Workspace != "" {
|
if config.Analysis && config.Workspace != "" {
|
||||||
return errors.New(fmt.Sprintf("Can't run with both --%s and --%s flags", AnalysisTapName, WorkspaceTapName))
|
return fmt.Errorf("Can't run with both --%s and --%s flags", AnalysisTapName, WorkspaceTapName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package fsUtils
|
package fsUtils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
@ -18,7 +17,7 @@ func EnsureDir(dirName string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
return errors.New(fmt.Sprintf("path exists but is not a directory: %s", dirName))
|
return fmt.Errorf("path exists but is not a directory: %s", dirName)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,5 @@ func IsTokenValid(tokenString string, envName string) bool {
|
|||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
if response.StatusCode != http.StatusOK {
|
return response.StatusCode == http.StatusOK
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func (d *Debouncer) SetOn() error {
|
|||||||
if d.canceled {
|
if d.canceled {
|
||||||
return fmt.Errorf("debouncer cancelled")
|
return fmt.Errorf("debouncer cancelled")
|
||||||
}
|
}
|
||||||
if d.running == true {
|
if d.running {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@ github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
|
|||||||
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
|
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
|
||||||
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
|
||||||
|
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 h1:yUdfgN0XgIJw7foRItutHYUIhlcKzcSf5vDpdhQAKTc=
|
||||||
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
|
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
|
||||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||||
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||||
@ -307,6 +308,7 @@ github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS4
|
|||||||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
||||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
|
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
|
||||||
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
|
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
|
||||||
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc=
|
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
@ -34,7 +34,7 @@ func (wh *EventWatchHelper) Filter(wEvent *WatchEvent) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.ToLower(event.Regarding.Kind) != strings.ToLower(wh.Kind) {
|
if strings.EqualFold(event.Regarding.Kind, wh.Kind) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,21 +3,22 @@ package kubernetes
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
"github.com/up9inc/mizu/shared"
|
"github.com/up9inc/mizu/shared"
|
||||||
"github.com/up9inc/mizu/shared/debounce"
|
"github.com/up9inc/mizu/shared/debounce"
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
core "k8s.io/api/core/v1"
|
core "k8s.io/api/core/v1"
|
||||||
"regexp"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const updateTappersDelay = 5 * time.Second
|
const updateTappersDelay = 5 * time.Second
|
||||||
|
|
||||||
type TappedPodChangeEvent struct {
|
type TappedPodChangeEvent struct {
|
||||||
Added []core.Pod
|
Added []core.Pod
|
||||||
Removed []core.Pod
|
Removed []core.Pod
|
||||||
}
|
}
|
||||||
|
|
||||||
// MizuTapperSyncer uses a k8s pod watch to update tapper daemonsets when targeted pods are removed or created
|
// MizuTapperSyncer uses a k8s pod watch to update tapper daemonsets when targeted pods are removed or created
|
||||||
@ -222,10 +223,14 @@ func (tapperSyncer *MizuTapperSyncer) watchPodsForTapping() {
|
|||||||
switch wEvent.Type {
|
switch wEvent.Type {
|
||||||
case EventAdded:
|
case EventAdded:
|
||||||
logger.Log.Debugf("Added matching pod %s, ns: %s", pod.Name, pod.Namespace)
|
logger.Log.Debugf("Added matching pod %s, ns: %s", pod.Name, pod.Namespace)
|
||||||
restartTappersDebouncer.SetOn()
|
if err := restartTappersDebouncer.SetOn(); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
case EventDeleted:
|
case EventDeleted:
|
||||||
logger.Log.Debugf("Removed matching pod %s, ns: %s", pod.Name, pod.Namespace)
|
logger.Log.Debugf("Removed matching pod %s, ns: %s", pod.Name, pod.Namespace)
|
||||||
restartTappersDebouncer.SetOn()
|
if err := restartTappersDebouncer.SetOn(); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
case EventModified:
|
case EventModified:
|
||||||
logger.Log.Debugf("Modified matching pod %s, ns: %s, phase: %s, ip: %s", pod.Name, pod.Namespace, pod.Status.Phase, pod.Status.PodIP)
|
logger.Log.Debugf("Modified matching pod %s, ns: %s, phase: %s, ip: %s", pod.Name, pod.Namespace, pod.Status.Phase, pod.Status.PodIP)
|
||||||
// Act only if the modified pod has already obtained an IP address.
|
// Act only if the modified pod has already obtained an IP address.
|
||||||
@ -235,7 +240,9 @@ func (tapperSyncer *MizuTapperSyncer) watchPodsForTapping() {
|
|||||||
// - Pod reaches ready state
|
// - Pod reaches ready state
|
||||||
// Ready/unready transitions might also trigger this event.
|
// Ready/unready transitions might also trigger this event.
|
||||||
if pod.Status.PodIP != "" {
|
if pod.Status.PodIP != "" {
|
||||||
restartTappersDebouncer.SetOn()
|
if err := restartTappersDebouncer.SetOn(); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case EventBookmark:
|
case EventBookmark:
|
||||||
break
|
break
|
||||||
@ -285,8 +292,8 @@ func (tapperSyncer *MizuTapperSyncer) updateCurrentlyTappedPods() (err error, ch
|
|||||||
tapperSyncer.CurrentlyTappedPods = podsToTap
|
tapperSyncer.CurrentlyTappedPods = podsToTap
|
||||||
tapperSyncer.nodeToTappedPodMap = GetNodeHostToTappedPodsMap(tapperSyncer.CurrentlyTappedPods)
|
tapperSyncer.nodeToTappedPodMap = GetNodeHostToTappedPodsMap(tapperSyncer.CurrentlyTappedPods)
|
||||||
tapperSyncer.TapPodChangesOut <- TappedPodChangeEvent{
|
tapperSyncer.TapPodChangesOut <- TappedPodChangeEvent{
|
||||||
Added: addedPods,
|
Added: addedPods,
|
||||||
Removed: removedPods,
|
Removed: removedPods,
|
||||||
}
|
}
|
||||||
return nil, true
|
return nil, true
|
||||||
}
|
}
|
||||||
|
@ -194,19 +194,19 @@ func (provider *Provider) GetMizuApiServerPodObject(opts *ApiServerOptions, moun
|
|||||||
|
|
||||||
cpuLimit, err := resource.ParseQuantity(opts.Resources.CpuLimit)
|
cpuLimit, err := resource.ParseQuantity(opts.Resources.CpuLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New(fmt.Sprintf("invalid cpu limit for %s container", opts.PodName))
|
return nil, fmt.Errorf("invalid cpu limit for %s container", opts.PodName)
|
||||||
}
|
}
|
||||||
memLimit, err := resource.ParseQuantity(opts.Resources.MemoryLimit)
|
memLimit, err := resource.ParseQuantity(opts.Resources.MemoryLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New(fmt.Sprintf("invalid memory limit for %s container", opts.PodName))
|
return nil, fmt.Errorf("invalid memory limit for %s container", opts.PodName)
|
||||||
}
|
}
|
||||||
cpuRequests, err := resource.ParseQuantity(opts.Resources.CpuRequests)
|
cpuRequests, err := resource.ParseQuantity(opts.Resources.CpuRequests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New(fmt.Sprintf("invalid cpu request for %s container", opts.PodName))
|
return nil, fmt.Errorf("invalid cpu request for %s container", opts.PodName)
|
||||||
}
|
}
|
||||||
memRequests, err := resource.ParseQuantity(opts.Resources.MemoryRequests)
|
memRequests, err := resource.ParseQuantity(opts.Resources.MemoryRequests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New(fmt.Sprintf("invalid memory request for %s container", opts.PodName))
|
return nil, fmt.Errorf("invalid memory request for %s container", opts.PodName)
|
||||||
}
|
}
|
||||||
|
|
||||||
command := []string{"./mizuagent", "--api-server"}
|
command := []string{"./mizuagent", "--api-server"}
|
||||||
@ -395,7 +395,7 @@ func (provider *Provider) CreatePod(ctx context.Context, namespace string, podSp
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (provider *Provider) CreateDeployment(ctx context.Context, namespace string, deploymentName string, podSpec *core.Pod) (*v1.Deployment, error) {
|
func (provider *Provider) CreateDeployment(ctx context.Context, namespace string, deploymentName string, podSpec *core.Pod) (*v1.Deployment, error) {
|
||||||
if _, keyExists := podSpec.ObjectMeta.Labels["app"]; keyExists == false {
|
if _, keyExists := podSpec.ObjectMeta.Labels["app"]; !keyExists {
|
||||||
return nil, errors.New("pod spec must contain 'app' label")
|
return nil, errors.New("pod spec must contain 'app' label")
|
||||||
}
|
}
|
||||||
podTemplate := &core.PodTemplateSpec{
|
podTemplate := &core.PodTemplateSpec{
|
||||||
@ -854,19 +854,19 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac
|
|||||||
)
|
)
|
||||||
cpuLimit, err := resource.ParseQuantity(resources.CpuLimit)
|
cpuLimit, err := resource.ParseQuantity(resources.CpuLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("invalid cpu limit for %s container", tapperPodName))
|
return fmt.Errorf("invalid cpu limit for %s container", tapperPodName)
|
||||||
}
|
}
|
||||||
memLimit, err := resource.ParseQuantity(resources.MemoryLimit)
|
memLimit, err := resource.ParseQuantity(resources.MemoryLimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("invalid memory limit for %s container", tapperPodName))
|
return fmt.Errorf("invalid memory limit for %s container", tapperPodName)
|
||||||
}
|
}
|
||||||
cpuRequests, err := resource.ParseQuantity(resources.CpuRequests)
|
cpuRequests, err := resource.ParseQuantity(resources.CpuRequests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("invalid cpu request for %s container", tapperPodName))
|
return fmt.Errorf("invalid cpu request for %s container", tapperPodName)
|
||||||
}
|
}
|
||||||
memRequests, err := resource.ParseQuantity(resources.MemoryRequests)
|
memRequests, err := resource.ParseQuantity(resources.MemoryRequests)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New(fmt.Sprintf("invalid memory request for %s container", tapperPodName))
|
return fmt.Errorf("invalid memory request for %s container", tapperPodName)
|
||||||
}
|
}
|
||||||
agentResourceLimits := core.ResourceList{
|
agentResourceLimits := core.ResourceList{
|
||||||
"cpu": cpuLimit,
|
"cpu": cpuLimit,
|
||||||
|
@ -4,11 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/up9inc/mizu/shared/debounce"
|
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/up9inc/mizu/shared/debounce"
|
||||||
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ func FilteredWatch(ctx context.Context, watcherCreator WatchCreator, targetNames
|
|||||||
|
|
||||||
go func(targetNamespace string) {
|
go func(targetNamespace string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
watchRestartDebouncer := debounce.NewDebouncer(1 * time.Minute, func() {})
|
watchRestartDebouncer := debounce.NewDebouncer(1*time.Minute, func() {})
|
||||||
|
|
||||||
for {
|
for {
|
||||||
watcher, err := watcherCreator.NewWatcher(ctx, targetNamespace)
|
watcher, err := watcherCreator.NewWatcher(ctx, targetNamespace)
|
||||||
@ -44,7 +45,7 @@ func FilteredWatch(ctx context.Context, watcherCreator WatchCreator, targetNames
|
|||||||
watcher.Stop()
|
watcher.Stop()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <- ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
@ -55,7 +56,9 @@ func FilteredWatch(ctx context.Context, watcherCreator WatchCreator, targetNames
|
|||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
if !watchRestartDebouncer.IsOn() {
|
if !watchRestartDebouncer.IsOn() {
|
||||||
watchRestartDebouncer.SetOn()
|
if err := watchRestartDebouncer.SetOn(); err != nil {
|
||||||
|
logger.Log.Error(err)
|
||||||
|
}
|
||||||
logger.Log.Debug("k8s watch channel closed, restarting watcher")
|
logger.Log.Debug("k8s watch channel closed, restarting watcher")
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
continue
|
continue
|
||||||
|
@ -345,7 +345,7 @@ func (p *RedisProtocol) Read() (packet *RedisPacket, err error) {
|
|||||||
if packet.Type == types[plusByte] {
|
if packet.Type == types[plusByte] {
|
||||||
packet.Keyword = RedisKeyword(strings.ToUpper(val))
|
packet.Keyword = RedisKeyword(strings.ToUpper(val))
|
||||||
if !isValidRedisKeyword(keywords, packet.Keyword) {
|
if !isValidRedisKeyword(keywords, packet.Keyword) {
|
||||||
err = errors.New(fmt.Sprintf("Unrecognized keyword: %s", string(packet.Command)))
|
err = fmt.Errorf("Unrecognized keyword: %s", string(packet.Command))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -363,7 +363,7 @@ func (p *RedisProtocol) Read() (packet *RedisPacket, err error) {
|
|||||||
|
|
||||||
if packet.Command != "" {
|
if packet.Command != "" {
|
||||||
if !isValidRedisCommand(commands, packet.Command) {
|
if !isValidRedisCommand(commands, packet.Command) {
|
||||||
err = errors.New(fmt.Sprintf("Unrecognized command: %s", string(packet.Command)))
|
err = fmt.Errorf("Unrecognized command: %s", string(packet.Command))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,6 @@ func (h *tcpReader) run(wg *sync.WaitGroup) {
|
|||||||
b := bufio.NewReader(h)
|
b := bufio.NewReader(h)
|
||||||
err := h.extension.Dissector.Dissect(b, h.isClient, h.tcpID, h.counterPair, h.superTimer, h.parent.superIdentifier, h.emitter, filteringOptions)
|
err := h.extension.Dissector.Dissect(b, h.isClient, h.tcpID, h.counterPair, h.superTimer, h.parent.superIdentifier, h.emitter, filteringOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
io.Copy(ioutil.Discard, b)
|
io.Copy(ioutil.Discard, b) //nolint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user