Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add namespace and placement info to debug endpoint in coordinator #1896

Merged
merged 15 commits into from
Aug 26, 2019

Conversation

benraskin92
Copy link
Collaborator

@benraskin92 benraskin92 commented Aug 20, 2019

What this PR does / why we need it:

This PR adds namespace and placement info the /debug/dump endpoint in coordinator.

  • Add tests to namespace.go
  • Add placement info
  • Add documentation for debug endpoint (if there isn't already)

Special notes for your reviewer:

Does this PR introduce a user-facing and/or backwards incompatible change?:

This PR adds placement and namespace information to the `/debug/dump` api endpoint within coordinator. 

Does this PR require updating code package or user-facing documentation?:

Will add documentation around `/debug/dump` API endpoint in a separate PR.

@@ -26,7 +26,7 @@ if [[ "$USE_JAEGER" = true ]] ; then
fi
fi

docker-compose -f docker-compose.yml up $DOCKER_ARGS m3coordinator01
docker-compose -f docker-compose.yml up --build -d --renew-anon-volumes m3coordinator01
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove before landing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@benraskin92 benraskin92 changed the title [DRAFT] Add namespace info to debug endpoint Add namespace and placement info to debug endpoint in coordinator Aug 21, 2019
@codecov
Copy link

codecov bot commented Aug 21, 2019

Codecov Report

Merging #1896 into master will decrease coverage by 4%.
The diff coverage is 0.9%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1896      +/-   ##
=========================================
- Coverage    61.5%   57.4%    -4.1%     
=========================================
  Files        1100    1039      -61     
  Lines      104214   91971   -12243     
=========================================
- Hits        64136   52873   -11263     
+ Misses      35843   35230     -613     
+ Partials     4235    3868     -367
Flag Coverage Δ
#aggregator 76% <ø> (-3.8%) ⬇️
#cluster 52.1% <ø> (-4.2%) ⬇️
#collector 54.9% <ø> (-8.8%) ⬇️
#dbnode 68.4% <0%> (+5.4%) ⬆️
#m3em 41.2% <ø> (-5.3%) ⬇️
#m3ninx 55.1% <ø> (-6%) ⬇️
#m3nsch 100% <ø> (+48.8%) ⬆️
#metrics 17.5% <ø> (ø) ⬆️
#msg 74.9% <ø> (+0.8%) ⬆️
#query 40.1% <0%> (-28.1%) ⬇️
#x 64.7% <1.6%> (+3.2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 94cadd4...1214da8. Read the comment docs.

logger.Fatal("unable to get placement opts", zap.Error(err))
}

debugWriter, err := xdebug.NewZipWriterWithDefaultSources(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done inside the if block; doesn't seem to be used otherwise

mux := http.NewServeMux()
if debugWriter != nil {
if err := debugWriter.RegisterHandler(debugEndpoint, mux); err != nil {
logger.Error("unable to register debug writer endpoint", zap.Error(err))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: print the config listen address here?

@@ -94,6 +94,9 @@ type Configuration struct {
// ListenAddress is the server listen address.
ListenAddress *listenaddress.Configuration `yaml:"listenAddress" validate:"nonzero"`

// The host and port on which to listen for debug endpoints.
DebugListenAddress string `yaml:"debugListenAddress"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good idea to get into the habit of editing annotated config when we add config settings (think it's quite behind unfortunately)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm working on restructuring the docs so lemme jot this down.

@@ -293,6 +289,20 @@ func (h *Handler) RegisterRoutes() error {
return nil
}

// PlacementOpts returns placement opts used in the various placement APIs.
func (h *Handler) PlacementOpts() (placement.HandlerOptions, error) {
placementOpts, err := placement.NewHandlerOptions(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return placement.NewHandlerOptions(..)

@@ -293,6 +289,20 @@ func (h *Handler) RegisterRoutes() error {
return nil
}

// PlacementOpts returns placement opts used in the various placement APIs.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: placement options in comment

if err != nil {
return err
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is nil suppose to be returned? If so can you drop a comment about why?

zap.String("address", cfg.DebugListenAddress), zap.Error(err))
} else {
logger.Info("debug server listening",
zap.String("address", cfg.DebugListenAddress),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: might be better to also include the endpoint, i.e. zap.String("endpoint", fmt.Sprintf("%s%s", cfg.DebugListenAddress, debugEndpoint))

src/x/debug/debug.go Show resolved Hide resolved
getHandler *namespace.GetHandler
}

// NewNamespaceInfoSource returns a Source for namespace information
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit; . at the end of comments

)

type namespaceInfoSource struct {
getHandler *namespace.GetHandler
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: handler rather than getHandler

@@ -2,6 +2,8 @@ listenAddress:
type: "config"
value: "0.0.0.0:7201"

debugListenAddress: "0.0.0.0:7205"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we put this on the main listen address on 7201?

}

w.Write(jsonData)
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be return w.Write(jsonData) since Write(...) can return an error


marshaler := jsonpb.Marshaler{EmitDefaults: true}
buf := new(bytes.Buffer)
marshaler.Marshal(buf, resp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check if this returns an error yeah?

marshaler := jsonpb.Marshaler{EmitDefaults: true}
marshaler.Marshal(w, resp)

return nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, here need to check marshaler.Marshal(...) so maybe just return marshaler.Marshal(w, resp)

// Write fetches data about the placement and writes it in the given writer.
// The data is formatted in json.
func (p *placementInfoSource) Write(w io.Writer) error {
placement, _, err := p.getHandler.Get(defaultM3DBServiceName, nil)
Copy link
Collaborator

@robskillington robskillington Aug 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should make the service name be part of the constructor so it can be reused? i.e. NewPlacementInfoSource(serviceName string, ...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also maybe make NewPlacementZipWriterWithDefaultSources(...) take a serviceNames []string param and create a new placement info source per service names specified?

@@ -68,9 +71,44 @@ func NewZipWriter(iopts instrument.Options) ZipWriter {
}
}

// NewPlacementZipWriterWithDefaultSources returns a zipWriter with the following
// debug sources already registered: CPU, heap, host, goroutines, namespace and placement info.
func NewPlacementZipWriterWithDefaultSources(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: NewPlacementAndNamespaceZipWriterWithDefaultSources(...) so it mentions namespace?


// Register debug dump handler.
h.router.HandleFunc(xdebug.DebugURL,
wrapped(debugWriter.HTTPHandler()).ServeHTTP)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robskillington Do I need to include .Methods() on this?

queryContextOptions models.QueryContextOptions
instrumentOpts instrument.Options
cpuProfileDuration time.Duration
placementServiceNames []string
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also create a debugOpts struct?

Copy link
Collaborator

@robskillington robskillington left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than one nit

"go.uber.org/zap"
)

const (
DebugURL = "/debug/dump"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not: need to add comment for exported var

@benraskin92 benraskin92 merged commit 8ad9b8e into master Aug 26, 2019
@benraskin92 benraskin92 deleted the braskin/m3db_debug_setup branch August 26, 2019 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants