Skip to content

Latest commit

 

History

History
191 lines (136 loc) · 10.3 KB

documents.md

File metadata and controls

191 lines (136 loc) · 10.3 KB

Documents & Trash

Dashboards and notebooks (see Dashboards & Notebooks) are the two most familiar kinds of Dynatrace document, but the Document Service stores documents of any type, including launchpads and app-specific documents (for example acme:config). dtctl can create, export, apply, and update documents of any type, and attach classification labels to them. Deleted documents move to the trash, retained for 30 days before permanent removal.

dtctl docs / Resources / Documents & Trash

Supported operations

Operation Resource Command syntax Description Mutating Access
create document dtctl create document Create resources from files yes write
delete document dtctl delete document Delete resources yes delete
describe document dtctl describe document Show details of a specific resource no read
edit document dtctl edit document Edit a resource yes write
get documents dtctl get documents Display one or many resources no read
history document dtctl history document Show version history of resources no read
restore document dtctl restore document Restore resources to a previous version yes write
share document dtctl share document Share documents with users, groups, or the environment yes write
unshare document dtctl unshare document Remove sharing from documents yes write
update document dtctl update document Update resources yes write
delete trash dtctl delete trash Delete resources yes delete
describe trash dtctl describe trash Show details of a specific resource no read
get trash dtctl get trash Display one or many resources no read
restore trash dtctl restore trash Restore resources to a previous version yes write

Flags

These commands take dtctl's global flags (-o/--output, --context, --jq, -v, and more). Some verbs add their own flags (apply, diff, query, inventory); see the verb in COMMANDS.md. Individual commands may take further flags of their own — run dtctl <verb> <resource> --help for the authoritative list.

Required token scopes

Safety level Scopes
delete document:documents:delete, document:trash.documents:delete
read document:documents:read, document:trash.documents:read
write document:documents:write, document:trash.documents:restore

These commands call other endpoints than the resource's, so they need these scopes instead of the ones for their access level. Some flags add a scope; see Flags that need an extra scope.

Command Scopes
dtctl share document document:documents:read, document:direct-shares:read, document:direct-shares:write
dtctl unshare document document:documents:read, document:direct-shares:read

Output

get document -o yaml emits the plain document (type, id, labels, and content) — use this form, not -o json, when the output will be fed back into apply/update document: JSON is wrapped in a result envelope that those commands cannot read back.

Examples

Every document carries a type; dashboard and notebook are built in, anything else (launchpad, acme:config, ...) is a custom type:

# List documents of a custom type with a raw Document API filter
dtctl get documents --filter "type == 'launchpad'"

Create a document — the type comes from --type or a type field in the file. create always creates (fails if the ID already exists); use apply for create-or-update, or update document for update-only:

# Create a launchpad document
dtctl create document -f launchpad.json --type launchpad

# Create from a payload that already contains a "type" field
dtctl create document -f my-app-config.yaml

# Create with a custom ID and template variables
dtctl create document -f config.yaml --type acme:config --id acme-config --set env=prod

Markdown documents take plain markdown, not YAML or JSON. With --type markdown (or a .md/.markdown file and no --type) the file is uploaded unchanged as text/markdown, so the Documents app renders it as written. The name comes from --name, else the first # heading, else the file name:

# Create a markdown document
dtctl create document -f strategy.md --name "Team strategy"

# Overwrite an existing markdown document (the body is replaced, history via --create-snapshot)
dtctl update document -f strategy.md --id <document-id> --create-snapshot
dtctl apply -f strategy.md --id <document-id>

apply and update document keep the document's name unless the file is created new. get document <id> -o yaml shows the markdown body under content: as a block string, and that export applies back as it is: a JSON or YAML file with type: markdown uploads its content string as the body, and its id, name, description and labels apply where no flag sets them. content must be a string.

dtctl get document <id> -o yaml > strategy.yaml
# edit strategy.yaml...
dtctl apply -f strategy.yaml

Round-trip: export, edit, and re-import (type and id are read from the file):

dtctl get document acme-config -o yaml > doc.yaml
# edit doc.yaml
dtctl apply -f doc.yaml            # create-or-update
dtctl update document -f doc.yaml  # update-only (fails if it doesn't exist)

Preview and diff before writing:

dtctl update document -f doc.yaml --dry-run
dtctl update document -f doc.yaml --show-diff

Labels are classification strings stored in a document's metadata. Passing --label replaces the entire label set (labels cannot be cleared, only replaced); omitting it leaves existing labels unchanged:

# Set labels at creation
dtctl create document -f config.yaml --type acme:config --label team-a --label env:prod

# Replace labels on an existing document
dtctl update document -f doc.yaml --label team-a --label env:prod

# Query labels back
dtctl get documents --add-fields labels
dtctl get document acme-config -o yaml   # labels appear at the top level

Share a document of any type with users, groups, or everyone in the environment. --environment takes one or both of two independent modes (--environment link,public for both), and each unshare mode undoes only its own (--all removes user and group shares only):

  • link creates an environment share at the --access level and prints its claim link (https://<environment>/ui/document/v0/#share=<id>; shareId and url in agent mode). Anyone in the environment who opens the link gets that access. A document has at most one link per access level: re-running reuses it, and a read and a read-write link can exist side by side. unshare --environment link deletes the link(s), optionally only the one at exactly --access.
  • public marks the document public (isPrivate=false): everyone in the environment can find and read it. unshare --environment public marks it private again.
dtctl share document my-launchpad --user user-sso-id --access read-write
dtctl share document my-launchpad --environment link
dtctl share document my-launchpad --environment link --access read-write
dtctl share document my-launchpad --environment public
dtctl unshare document my-launchpad --environment link
dtctl unshare document my-launchpad --environment public
dtctl unshare document my-launchpad --environment link,public   # undo both

To share an applied notebook or dashboard with the environment, apply the file, then run share document <id> --environment link,public on the IDs apply -o json returns. --environment is experimental: a context pinned to --min-stability stable (and every embedded request, whose floor defaults to stable) rejects it unless the flag is admitted as an exception. Admit it before applying, so the document is not left applied but unshared:

dtctl config set-context prod-agent --stability-exception 'share document --environment'

See STABILITY.md for floors and exceptions.

Version history and deletion (same commands work for document or trash):

dtctl history document doc-123
dtctl restore document doc-123 5

dtctl delete document doc-123
dtctl get trash
dtctl get trash --deleted-since 7d
dtctl describe trash doc-123
dtctl restore trash doc-123
dtctl delete trash doc-123 --permanent

get trash --deleted-after/--deleted-before are deprecated in favour of --deleted-since/--deleted-until (removal planned in 1.0.0). --deleted-after DATE and --deleted-since DATE mean the same thing, but the upper bound does not: --deleted-before DATE stops at midnight at the start of DATE, while --deleted-until DATE includes the whole day. To keep the old bound, pass the midnight explicitly: --deleted-before 2024-12-31 becomes --deleted-until 2024-12-31T00:00:00Z.

Notes

apply vs. update document

Both go through the same applier, so dry-run, --show-diff, template rendering (--set), safety checks, and labels behave identically. They differ only in intent:

apply -f update document -f
Target doesn't exist Creates it Fails (no accidental create on a typo'd ID)
Type resolution Payload type, or --type --type, or payload type
ID resolution Payload id, or --id --id, or payload id
# Force a type for a file that carries only raw content
dtctl apply -f content.json --type acme:config --id acme-config
dtctl update document -f content.json --type acme:config --id acme-config

--type cannot be combined with array (bulk) input.

Label update semantics

Labels cannot be cleared, only replaced -- the Document Service offers no clear-labels affordance.

Create sets labels via a follow-up update: the create API cannot set labels directly, so dtctl issues a create and then a label update. This is not atomic. If the label step fails, the document already exists and the error names it.