Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
naemono committed Nov 7, 2022
1 parent dc6aa72 commit 3a9ac85
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
59 changes: 48 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ Usage:
eck-diagnostics [flags]
Flags:
--diagnostic-image string Diagnostic image to be used for stack diagnostics, see run-stack-diagnostics (default "docker.elastic.co/eck-dev/support-diagnostics:8.1.4")
--eck-version string ECK version in use, will try to autodetect if not specified
-h, --help help for eck-diagnostics
--kubeconfig string optional path to kube config, defaults to $HOME/.kube/config
-o, --operator-namespaces strings Comma-separated list of namespace(s) in which operator(s) are running (default [elastic-system])
--output-directory string Path where to output diagnostic results
-r, --resources-namespaces strings Comma-separated list of namespace(s) in which resources are managed
--run-agent-diagnostics Run diagnostics on deployed Elastic Agents. Warning: credentials will not be redacted and appear as plain text in the archive
--run-stack-diagnostics Run diagnostics on deployed Elasticsearch clusters and Kibana instances, requires deploying diagnostic Pods into the cluster (default true)
--verbose Verbose mode
--diagnostic-image string Diagnostic image to be used for stack diagnostics, see run-stack-diagnostics (default "docker.elastic.co/eck-dev/support-diagnostics:8.4.0")
--eck-version string ECK version in use, will try to autodetect if not specified
-f, --filters strings Comma-separated list of filters in format "type=type, name=name" (Supported types [agent apm beat elasticsearch enterprisesearch kibana maps])
-h, --help help for eck-diagnostics
--kubeconfig string optional path to kube config, defaults to $HOME/.kube/config
-o, --operator-namespaces strings Comma-separated list of namespace(s) in which operator(s) are running (default [elastic-system])
--output-directory string Path where to output diagnostic results
-r, --resources-namespaces strings Comma-separated list of namespace(s) in which resources are managed
--run-agent-diagnostics Run diagnostics on deployed Elastic Agents. Warning: credentials will not be redacted and appear as plain text in the archive
--run-stack-diagnostics Run diagnostics on deployed Elasticsearch clusters and Kibana instances, requires deploying diagnostic Pods into the cluster (default true)
--stack-diagnostics-timeout duration Maximum time to wait for Elaticsearch and Kibana diagnostics to complete (default 5m0s)
--verbose Verbose mode
```

## Information collected by eck-diagnostics
Expand Down Expand Up @@ -82,4 +84,39 @@ The ECK related custom resources are included in those namespaces as well:
* Kibana

### Logs
In the operator namespaces (`-o, --operator-namespaces`) all logs are collected, while in the workload resource namespaces only logs from Pods managed by ECK are collected.
In the operator namespaces (`-o, --operator-namespaces`) all logs are collected, while in the workload resource namespaces only logs from Pods managed by ECK are collected.

## Filtering collected resources

The resources in the specified namespaces that are collected by eck-diagnostics can be filtered with the `-f, --filters` flag.

### Usage Example

The following example will run the diagnostics for Elastic resources in namespace `a`, and will only return resources associated with an Elasticsearch cluster named `mycluster`.

```shell
eck-diagnostics -r a -f "type=elasticsearch,name=mycluster"
```

### Filtered resources

Only a certain number of Kubernetes resources support filtering when filtering by an Elastic custom resource. Along with the named Elastic custom resource type, the following resources will be returned that are associated:

* ConfigMap
* ControllerRevision
* Deployment
* DaemonSet
* Endpoint
* Pod
* PersistentVolumeClaim
* Replicaset
* Service
* StatefulSet

The following resources are returned unfiltered:

* Event
* NetworkPolicy
* PersistentVolume
* ServiceAccount
* Secret (metadata only)
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"fmt"
"log"
"os"
"time"
Expand Down Expand Up @@ -34,7 +35,7 @@ func main() {
cmd.Flags().BoolVar(&diagParams.RunAgentDiagnostics, "run-agent-diagnostics", false, "Run diagnostics on deployed Elastic Agents. Warning: credentials will not be redacted and appear as plain text in the archive")
cmd.Flags().StringSliceVarP(&diagParams.OperatorNamespaces, "operator-namespaces", "o", []string{"elastic-system"}, "Comma-separated list of namespace(s) in which operator(s) are running")
cmd.Flags().StringSliceVarP(&diagParams.ResourcesNamespaces, "resources-namespaces", "r", nil, "Comma-separated list of namespace(s) in which resources are managed")
cmd.Flags().StringSliceVarP(&filters, "filters", "f", nil, `Comma-separated list of filters in format "type=type, name=name" (Supported types 'elasticsearch')`)
cmd.Flags().StringSliceVarP(&filters, "filters", "f", nil, fmt.Sprintf(`Comma-separated list of filters in format "type=type, name=name" (Supported types %v)`, internal_filters.ValidTypes))
cmd.Flags().StringVar(&diagParams.ECKVersion, "eck-version", "", "ECK version in use, will try to autodetect if not specified")
cmd.Flags().StringVar(&diagParams.OutputDir, "output-directory", "", "Path where to output diagnostic results")
cmd.Flags().StringVar(&diagParams.Kubeconfig, "kubeconfig", "", "optional path to kube config, defaults to $HOME/.kube/config")
Expand Down
2 changes: 1 addition & 1 deletion internal/diag.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func Run(params Params) error {

operatorVersions = append(operatorVersions, detectECKVersion(clientSet, ns, params.ECKVersion))

zipFile.Add(getResources(kubectl.Get, ns, params.Filter, []string{
zipFile.Add(getResources(kubectl.Get, ns, filters.Filter{}, []string{
"statefulsets",
"pods",
"services",
Expand Down
7 changes: 4 additions & 3 deletions internal/filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

var (
validTypes = []string{"agent", "apm", "beat", "elasticsearch", "enterprisesearch", "kibana", "maps"}
// ValidTypes are the valid types of Elastic resources that are supported by the filtering system.
ValidTypes = []string{"agent", "apm", "beat", "elasticsearch", "enterprisesearch", "kibana", "maps"}
elasticTypeKey = "common.k8s.elastic.co/type"
elasticsearchNameFormat = "%s.k8s.elastic.co/cluster-name"
elasticNameFormat = "%s.k8s.elastic.co/name"
Expand Down Expand Up @@ -85,8 +86,8 @@ func (f Filter) validate() (Filter, error) {
}

func validateType(typ string) error {
if !slices.Contains(validTypes, typ) {
return fmt.Errorf("invalid type: %s, supported types: %v", typ, validTypes)
if !slices.Contains(ValidTypes, typ) {
return fmt.Errorf("invalid type: %s, supported types: %v", typ, ValidTypes)
}
return nil
}
Expand Down

0 comments on commit 3a9ac85

Please sign in to comment.