Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Mizu
Commits
749bee6d
Unverified
Commit
749bee6d
authored
3 years ago
by
Igor Gov
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Using rlog in agent and tapper & removing unreferenced code (#289)
* .
parent
043b845c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
agent/main.go
+6
-23
agent/main.go
agent/pkg/rules/rulesHTTP.go
+2
-1
agent/pkg/rules/rulesHTTP.go
agent/pkg/utils/har.go
+3
-4
agent/pkg/utils/har.go
agent/pkg/utils/socket_client.go
+7
-8
agent/pkg/utils/socket_client.go
agent/pkg/utils/utils.go
+7
-7
agent/pkg/utils/utils.go
cli/mizu/controlSocket.go
+0
-42
cli/mizu/controlSocket.go
with
25 additions
and
85 deletions
+25
-85
agent/main.go
+
6
-
23
View file @
749bee6d
...
...
@@ -65,6 +65,7 @@ func main() {
hostApi
(
nil
)
}
else
if
*
tapperMode
{
rlog
.
Infof
(
"Starting tapper, websocket address: %s"
,
*
apiServerAddress
)
if
*
apiServerAddress
==
""
{
panic
(
"API server address must be provided with --api-server-address when using --tap"
)
}
...
...
@@ -77,13 +78,13 @@ func main() {
filteredOutputItemsChannel
:=
make
(
chan
*
tapApi
.
OutputChannelItem
)
tap
.
StartPassiveTapper
(
tapOpts
,
filteredOutputItemsChannel
,
extensions
,
filteringOptions
)
socketConnection
,
err
:=
shared
.
ConnectToSocketServer
(
*
apiServerAddress
,
shared
.
DEFAULT_SOCKET_RETRIES
,
shared
.
DEFAULT_SOCKET_RETRY_SLEEP_TIME
,
false
)
socketConnection
,
err
:=
utils
.
ConnectToSocketServer
(
*
apiServerAddress
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"Error connecting to socket server at %s %v"
,
*
apiServerAddress
,
err
))
}
rlog
.
Infof
(
"Connected successfully to websocket %s"
,
*
apiServerAddress
)
go
pipeTapChannelToSocket
(
socketConnection
,
filteredOutputItemsChannel
)
// go pipeOutboundLinksChannelToSocket(socketConnection, outboundLinkOutputChannel)
}
else
if
*
apiServerMode
{
api
.
StartResolving
(
*
namespace
)
...
...
@@ -122,7 +123,7 @@ func loadExtensions() {
extensionsMap
=
make
(
map
[
string
]
*
tapApi
.
Extension
)
for
i
,
file
:=
range
files
{
filename
:=
file
.
Name
()
log
.
Print
f
(
"Loading extension: %s
\n
"
,
filename
)
r
log
.
Info
f
(
"Loading extension: %s
\n
"
,
filename
)
extension
:=
&
tapApi
.
Extension
{
Path
:
path
.
Join
(
extensionsDir
,
filename
),
}
...
...
@@ -290,7 +291,7 @@ func pipeTapChannelToSocket(connection *websocket.Conn, messageDataChannel <-cha
for
messageData
:=
range
messageDataChannel
{
marshaledData
,
err
:=
models
.
CreateWebsocketTappedEntryMessage
(
messageData
)
if
err
!=
nil
{
rlog
.
Info
f
(
"error converting message to json %s, (%v,%+v)
\n
"
,
err
,
err
,
err
)
rlog
.
Error
f
(
"error converting message to json
%v, err:
%s, (%v,%+v)
"
,
messageData
,
err
,
err
,
err
)
continue
}
...
...
@@ -298,26 +299,8 @@ func pipeTapChannelToSocket(connection *websocket.Conn, messageDataChannel <-cha
// and goes into the intermediate WebSocket.
err
=
connection
.
WriteMessage
(
websocket
.
TextMessage
,
marshaledData
)
if
err
!=
nil
{
rlog
.
Info
f
(
"error sending message through socket server %s, (%v,%+v)
\n
"
,
err
,
err
,
err
)
rlog
.
Error
f
(
"error sending message through socket server
%v, err:
%s, (%v,%+v)
"
,
messageData
,
err
,
err
,
err
)
continue
}
}
}
func
pipeOutboundLinksChannelToSocket
(
connection
*
websocket
.
Conn
,
outboundLinkChannel
<-
chan
*
tap
.
OutboundLink
)
{
for
outboundLink
:=
range
outboundLinkChannel
{
if
outboundLink
.
SuggestedProtocol
==
tap
.
TLSProtocol
{
marshaledData
,
err
:=
models
.
CreateWebsocketOutboundLinkMessage
(
outboundLink
)
if
err
!=
nil
{
rlog
.
Infof
(
"Error converting outbound link to json %s, (%v,%+v)"
,
err
,
err
,
err
)
continue
}
err
=
connection
.
WriteMessage
(
websocket
.
TextMessage
,
marshaledData
)
if
err
!=
nil
{
rlog
.
Infof
(
"error sending outbound link message through socket server %s, (%v,%+v)"
,
err
,
err
,
err
)
continue
}
}
}
}
This diff is collapsed.
Click to expand it.
agent/pkg/rules/rulesHTTP.go
+
2
-
1
View file @
749bee6d
...
...
@@ -4,6 +4,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/romana/rlog"
"reflect"
"regexp"
"strings"
...
...
@@ -65,7 +66,7 @@ func MatchRequestPolicy(harEntry har.Entry, service string) []RulesMatched {
if
err
!=
nil
{
continue
}
fmt
.
Println
(
matchValue
,
rule
.
Value
)
rlog
.
Info
(
matchValue
,
rule
.
Value
)
}
else
{
val
:=
fmt
.
Sprint
(
out
)
matchValue
,
err
=
regexp
.
MatchString
(
rule
.
Value
,
val
)
...
...
This diff is collapsed.
Click to expand it.
agent/pkg/utils/har.go
+
3
-
4
View file @
749bee6d
...
...
@@ -4,13 +4,12 @@ import (
"bytes"
"errors"
"fmt"
"strconv"
"strings"
"time"
"github.com/google/martian/har"
"github.com/romana/rlog"
"github.com/up9inc/mizu/tap/api"
"strconv"
"strings"
"time"
)
// Keep it because we might want cookies in the future
...
...
This diff is collapsed.
Click to expand it.
shared
/socket_client.go
→
agent/pkg/utils
/socket_client.go
+
7
-
8
View file @
749bee6d
package
shared
package
utils
import
(
"fmt"
"github.com/gorilla/websocket"
"github.com/romana/rlog"
"time"
)
...
...
@@ -11,24 +11,23 @@ const (
DEFAULT_SOCKET_RETRY_SLEEP_TIME
=
time
.
Second
*
10
)
func
ConnectToSocketServer
(
address
string
,
retries
int
,
retrySleepTime
time
.
Duration
,
hideTimeoutErrors
bool
)
(
*
websocket
.
Conn
,
error
)
{
func
ConnectToSocketServer
(
address
string
)
(
*
websocket
.
Conn
,
error
)
{
var
err
error
var
connection
*
websocket
.
Conn
try
:=
0
// Connection to server fails if client pod is up before server.
// Retries solve this issue.
for
try
<
retries
{
for
try
<
DEFAULT_SOCKET_RETRIES
{
rlog
.
Infof
(
"Trying to connect to websocket: %s, attempt: %v/%v"
,
address
,
try
,
DEFAULT_SOCKET_RETRIES
)
connection
,
_
,
err
=
websocket
.
DefaultDialer
.
Dial
(
address
,
nil
)
if
err
!=
nil
{
rlog
.
Warnf
(
"Failed connecting to websocket: %s, attempt: %v/%v, err: %s, (%v,%+v)"
,
address
,
try
,
DEFAULT_SOCKET_RETRIES
,
err
,
err
,
err
)
try
++
if
!
hideTimeoutErrors
{
fmt
.
Printf
(
"Failed connecting to websocket server: %s, (%v,%+v)
\n
"
,
err
,
err
,
err
)
}
}
else
{
break
}
time
.
Sleep
(
retrySleepTime
)
time
.
Sleep
(
DEFAULT_SOCKET_RETRY_SLEEP_TIME
)
}
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
agent/pkg/utils/utils.go
+
7
-
7
View file @
749bee6d
...
...
@@ -4,7 +4,6 @@ import (
"context"
"github.com/gin-gonic/gin"
"github.com/romana/rlog"
"log"
"net/http"
"net/url"
"os"
...
...
@@ -18,8 +17,8 @@ import (
func
StartServer
(
app
*
gin
.
Engine
)
{
signals
:=
make
(
chan
os
.
Signal
,
2
)
signal
.
Notify
(
signals
,
os
.
Interrupt
,
// this catch ctrl + c
syscall
.
SIGTSTP
,
// this catch ctrl + z
os
.
Interrupt
,
// this catch ctrl + c
syscall
.
SIGTSTP
,
// this catch ctrl + z
)
srv
:=
&
http
.
Server
{
...
...
@@ -36,8 +35,9 @@ func StartServer(app *gin.Engine) {
}()
// Run server.
rlog
.
Infof
(
"Starting the server..."
)
if
err
:=
app
.
Run
(
":8899"
);
err
!=
nil
{
log
.
Printf
(
"Oops...
Server is not running! Reason: %v"
,
err
)
r
log
.
Errorf
(
"
Server is not running! Reason: %v"
,
err
)
}
}
...
...
@@ -54,15 +54,15 @@ func ReverseSlice(data interface{}) {
func
CheckErr
(
e
error
)
{
if
e
!=
nil
{
log
.
Print
f
(
"%v"
,
e
)
r
log
.
Info
f
(
"%v"
,
e
)
//panic(e)
}
}
func
SetHostname
(
address
,
newHostname
string
)
string
{
replacedUrl
,
err
:=
url
.
Parse
(
address
)
if
err
!=
nil
{
log
.
Print
f
(
"error replacing hostname to %s in address %s, returning original %v"
,
newHostname
,
address
,
err
)
if
err
!=
nil
{
r
log
.
Info
f
(
"error replacing hostname to %s in address %s, returning original %v"
,
newHostname
,
address
,
err
)
return
address
}
replacedUrl
.
Host
=
newHostname
...
...
This diff is collapsed.
Click to expand it.
cli/mizu/controlSocket.go
deleted
100644 → 0
+
0
-
42
View file @
043b845c
package
mizu
import
(
"encoding/json"
"github.com/gorilla/websocket"
"github.com/up9inc/mizu/shared"
core
"k8s.io/api/core/v1"
"time"
)
type
ControlSocket
struct
{
connection
*
websocket
.
Conn
}
func
CreateControlSocket
(
socketServerAddress
string
)
(
*
ControlSocket
,
error
)
{
connection
,
err
:=
shared
.
ConnectToSocketServer
(
socketServerAddress
,
30
,
2
*
time
.
Second
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
else
{
return
&
ControlSocket
{
connection
:
connection
},
nil
}
}
func
(
controlSocket
*
ControlSocket
)
SendNewTappedPodsListMessage
(
pods
[]
core
.
Pod
)
error
{
podInfos
:=
make
([]
shared
.
PodInfo
,
0
)
for
_
,
pod
:=
range
pods
{
podInfos
=
append
(
podInfos
,
shared
.
PodInfo
{
Name
:
pod
.
Name
,
Namespace
:
pod
.
Namespace
})
}
tapStatus
:=
shared
.
TapStatus
{
Pods
:
podInfos
}
socketMessage
:=
shared
.
CreateWebSocketStatusMessage
(
tapStatus
)
jsonMessage
,
err
:=
json
.
Marshal
(
socketMessage
)
if
err
!=
nil
{
return
err
}
err
=
controlSocket
.
connection
.
WriteMessage
(
websocket
.
TextMessage
,
jsonMessage
)
if
err
!=
nil
{
return
err
}
return
nil
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help