Skip to content

Commit

Permalink
#340: remove noisy logs but in all cases be able to reactivate them u…
Browse files Browse the repository at this point in the history
…sing: PRINT_QUIET_LOGS and PRINT_HTTP_LOGS - also disable zipkin if TRACE_ADDR is an empty string
  • Loading branch information
binocarlos committed Mar 23, 2018
1 parent 6bc0663 commit 7e3a713
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 37 deletions.
22 changes: 11 additions & 11 deletions cmd/dotmesh-server/pkg/main/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,40 +183,40 @@ func (s *InMemoryState) getOne(ctx context.Context, fs string) (DotmeshVolume, e
return DotmeshVolume{}, err
}

log.Printf("[getOne] starting for %v", fs)
quietLogger(fmt.Sprintf("[getOne] starting for %v", fs))

if tlf, clone, err := s.registry.LookupFilesystemById(fs); err == nil {
authorized, err := tlf.Authorize(ctx)
if err != nil {
return DotmeshVolume{}, err
}
if !authorized {
log.Printf(
quietLogger(fmt.Sprintf(
"[getOne] notauth for %v", fs,
)
))
return DotmeshVolume{}, PermissionDenied{}
}
// if not exists, 0 is fine
s.globalDirtyCacheLock.Lock()
log.Printf(
quietLogger(fmt.Sprintf(
"[getOne] looking up %s with master %s in %s",
fs, master, *s.globalDirtyCache,
)
))
dirty, ok := (*s.globalDirtyCache)[fs]
var dirtyBytes int64
var sizeBytes int64
if ok {
dirtyBytes = dirty.DirtyBytes
sizeBytes = dirty.SizeBytes
log.Printf(
quietLogger(fmt.Sprintf(
"[getOne] got dirtyInfo %d,%d for %s with master %s in %s",
sizeBytes, dirtyBytes, fs, master, *s.globalDirtyCache,
)
))
} else {
log.Printf(
quietLogger(fmt.Sprintf(
"[getOne] %s was not in %s",
fs, *s.globalDirtyCache,
)
))
}
s.globalDirtyCacheLock.Unlock()
// if not exists, 0 is fine
Expand Down Expand Up @@ -269,9 +269,9 @@ func (s *InMemoryState) getOne(ctx context.Context, fs string) (DotmeshVolume, e
d.ServerStatuses[server.Id] = status
s.globalStateCacheLock.Unlock()
}
log.Printf(
quietLogger(fmt.Sprintf(
"[getOne] here is your volume: %s", d,
)
))
return d, nil
} else {
return DotmeshVolume{}, fmt.Errorf("Unable to find filesystem name for id %s", fs)
Expand Down
67 changes: 45 additions & 22 deletions cmd/dotmesh-server/pkg/main/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,61 @@ func (state *InMemoryState) runServer() {
log.Printf("Error while registering services %s", err)
}

tracer := opentracing.GlobalTracer()

router := mux.NewRouter()
router.Handle("/rpc",
middleware.FromHTTPRequest(tracer, "rpc")(NewAuthHandler(r)),
)

// only use the zipkin middleware if we have a TRACE_ADDR
if os.Getenv("TRACE_ADDR") != "" {
tracer := opentracing.GlobalTracer()

router.Handle("/rpc",
middleware.FromHTTPRequest(tracer, "rpc")(NewAuthHandler(r)),
)

router.Handle(
"/filesystems/{filesystem}/{fromSnap}/{toSnap}",
middleware.FromHTTPRequest(tracer, "zfs-sender")(
NewAuthHandler(state.NewZFSSendingServer()),
),
).Methods("GET")

router.Handle(
"/filesystems/{filesystem}/{fromSnap}/{toSnap}",
middleware.FromHTTPRequest(tracer, "zfs-receiver")(
NewAuthHandler(state.NewZFSReceivingServer()),
),
).Methods("POST")

} else {
router.Handle("/rpc", NewAuthHandler(r))

router.Handle(
"/filesystems/{filesystem}/{fromSnap}/{toSnap}",
NewAuthHandler(state.NewZFSSendingServer()),
).Methods("GET")

router.Handle(
"/filesystems/{filesystem}/{fromSnap}/{toSnap}",
NewAuthHandler(state.NewZFSReceivingServer()),
).Methods("POST")

}

router.HandleFunc("/status",
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "OK")
},
)

router.Handle(
"/filesystems/{filesystem}/{fromSnap}/{toSnap}",
middleware.FromHTTPRequest(tracer, "zfs-sender")(
NewAuthHandler(state.NewZFSSendingServer()),
),
).Methods("GET")

router.Handle(
"/filesystems/{filesystem}/{fromSnap}/{toSnap}",
middleware.FromHTTPRequest(tracer, "zfs-receiver")(
NewAuthHandler(state.NewZFSReceivingServer()),
),
).Methods("POST")
if os.Getenv("PRINT_HTTP_LOGS") != "" {
loggingRouter := handlers.LoggingHandler(getLogfile("requests"), router)
err = http.ListenAndServe(fmt.Sprintf(":%s", SERVER_PORT), loggingRouter)
} else {
err = http.ListenAndServe(fmt.Sprintf(":%s", SERVER_PORT), router)
}

loggedRouter := handlers.LoggingHandler(getLogfile("requests"), router)
err = http.ListenAndServe(":32607", loggedRouter)
if err != nil {
out(fmt.Sprintf("Unable to listen on port 32607: '%s'\n", err))
log.Fatalf("Unable to listen on port 32607: '%s'", err)
out(fmt.Sprintf("Unable to listen on port %s: '%s'\n", SERVER_PORT, err))
log.Fatalf("Unable to listen on port %s: '%s'", SERVER_PORT, err)
}
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/dotmesh-server/pkg/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const ZPOOL = "zpool"
const META_KEY_PREFIX = "io.dotmesh:meta-"
const ETCD_PREFIX = "/dotmesh.io"
const CONTAINER_MOUNT_PREFIX = "/var/dotmesh"
const SERVER_PORT = "32607"
const SERVER_PORT_OLD = "6969"

var LOG_TO_STDOUT bool
var POOL string
Expand Down
4 changes: 2 additions & 2 deletions cmd/dotmesh-server/pkg/main/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ func (d *DotmeshRPC) AllDotsAndBranches(
args *struct{},
result *VolumesAndBranches,
) error {
log.Printf("[AllDotsAndBranches] starting...")
quietLogger("[AllDotsAndBranches] starting...")

vac := VolumesAndBranches{}

Expand Down Expand Up @@ -1340,7 +1340,7 @@ func (d *DotmeshRPC) AllDotsAndBranches(
vac.Dots = append(vac.Dots, tlf)
}
*result = vac
log.Printf("[AllDotsAndBranches] finished!")
quietLogger("[AllDotsAndBranches] finished!")
return nil
}

Expand Down
12 changes: 10 additions & 2 deletions cmd/dotmesh-server/pkg/main/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func deduceUrl(ctx context.Context, hostnames []string, mode, user, apiKey strin
}
} else {
urlsToTry = []string{
fmt.Sprintf("http://%s:%d", hostname, 32607),
fmt.Sprintf("http://%s:%d", hostname, 6969),
fmt.Sprintf("http://%s:%d", hostname, SERVER_PORT),
fmt.Sprintf("http://%s:%d", hostname, SERVER_PORT_OLD),
}
}

Expand Down Expand Up @@ -630,3 +630,11 @@ func (v VolumeName) StringWithoutAdmin() string {
return fmt.Sprintf("%s/%s", v.Namespace, v.Name)
}
}

// we are removing lots of logging but let's enable them to be switched back on
// if the PRINT_QUIET_LOGS env is not empty
func quietLogger(logMessage string) {
if os.Getenv("PRINT_QUIET_LOGS") != "" {
log.Printf(logMessage)
}
}

0 comments on commit 7e3a713

Please sign in to comment.