Repository: DataDog/dd-agent

Issue:
Docker daemon tag extending/improvement
**Output of the [info page](https://help.datadoghq.com/hc/en-us/articles/203764635-Agent-Status-and-Information) **

===================
Collector (v 5.9.1)
===================

  Status date: 2016-12-02 15:30:17 (71512s ago)
  Pid: 20277
  Platform: Linux-3.16.0-4-amd64-x86_64-with-debian-8.4
  Python Version: 2.7.12, 64bit
  Logs: <stderr>, /var/log/datadog/collector.log, syslog:/dev/log

  Clocks
  ======

    NTP offset: 0.0106 s
    System UTC time: 2016-12-14 11:22:10.535332

  Paths
  =====

    conf.d: /etc/dd-agent/conf.d
    checks.d: /opt/datadog-agent/agent/checks.d

  Hostnames
  =========

    ec2-hostname: ip-10-0-100-35.us-west-2.compute.internal
    local-ipv4: 10.0.100.35
    local-hostname: ip-10-0-100-35.us-west-2.compute.internal
    socket-hostname: ip-10-0-100-35
    hostname: ip-10-0-100-35.us-west-2.compute.internal
    instance-id: i-04424e1363741d8f5
    socket-fqdn: ip-10-0-100-35.us-west-2.compute.internal

  Checks
  ======

    network
    -------
      - instance #0 [OK]
      - Collected 39 metrics, 0 events & 1 service check

    process
    -------
      - instance #0 [OK]
      - instance #1 [OK]
      - instance #2 [OK]
      - Collected 33 metrics, 0 events & 4 service checks

    ntp
    ---
      - Collected 0 metrics, 0 events & 1 service check

    disk
    ----
      - instance #0 [OK]
      - Collected 40 metrics, 0 events & 1 service check

    docker_daemon
    -------------
      - instance #0 [OK]
      - Collected 81 metrics, 1 event & 2 service checks


  Emitters
  ========

    - http_emitter [OK]

===================
Dogstatsd (v 5.9.1)
===================

  Status date: 2016-12-14 11:22:07 (3s ago)
  Pid: 8146
  Platform: Linux-3.16.0-4-amd64-x86_64-with-debian-8.4
  Python Version: 2.7.12, 64bit
  Logs: <stderr>, /var/log/datadog/dogstatsd.log, syslog:/dev/log

  Flush count: 21249
  Packet Count: 0
  Packets per second: 0.0
  Metric count: 1
  Event count: 0
  Service check count: 0

===================
Forwarder (v 5.9.1)
===================

  Status date: 2016-12-14 11:22:09 (2s ago)
  Pid: 8145
  Platform: Linux-3.16.0-4-amd64-x86_64-with-debian-8.4
  Python Version: 2.7.12, 64bit
  Logs: <stderr>, /var/log/datadog/forwarder.log, syslog:/dev/log

  Queue Size: 0 bytes
  Queue Length: 0
  Flush Count: 62252
  Transactions received: 21248
  Transactions flushed: 21248
  Transactions rejected: 0

**Additional environment details (Operating System, Cloud provider, etc):**

Linux Ubuntu and Amazon Linux, AWS

**Steps to reproduce the issue:**
1. Create docker image in AWS ECR
2. Run docker image from the ECR
3. Collect metrics through the docker_daemon checker

**Describe the results you received:**
Tag docker_image looks like this 
"{aws_account_id}.dkr.ecr.{aw_region}.amazonaws.com/{container_name}:{image_tag}"
It is very long string. And if ECR (repository url) is the same for all containers it is hard to determine them.

**Describe the results you expected:**
Something like this: "{container_name}:{image_tag}"
Shorter and simple. Maybe additional tag "container_name" instead of changing the "docker_image" tag

**Additional information you deem important (e.g. issue happens only occasionally):**
I understand that it is not common problem. But it would be great to have tag with simple container name.


Discussion:
+1

it would be convenient if it could be configurable using docker_daemon.yaml, for example, by having simple boolean field that could omit docker repo name, or, by defining some regexp-like converter
Hi @opteemister 
Thanks for the detailed report. When you say container name you mean the image name but without the docker repository right? Because we already have a container_name tag which is (erm) the container name.

We could add a `short_image_name` tag that would strip the repo, and make it available [here](https://github.com/DataDog/dd-agent/blob/5.10.1/conf.d/docker_daemon.yaml.example#L114-L123). Would that work for you?
Hi, @hkaj 

Yes, you are right I meant image name without docker repository. It would be great to have short_image_name.
But not for Performance metrics.
For this https://github.com/DataDog/dd-agent/blob/5.10.1/conf.d/docker_daemon.yaml.example#L125 
We use these tags for docker.containers.running metric. I think that metric is in that part.

Thank you.
It is. We'll add it for both then.
Thank you!
Hi, @hkaj 
When will this be available? 

Resolving patch:
diff --git a/utils/dockerutil.py b/utils/dockerutil.py
--- a/utils/dockerutil.py
+++ b/utils/dockerutil.py
@@ -573,15 +573,19 @@ def image_tag_extractor(self, entity, key):
 
         return None
 
-    def image_name_extractor(self, co):
+    def image_name_extractor(self, co, short=False):
         """
         Returns the image name for a container, either directly from the
         container's Image property or by inspecting the image entity if
         the reference is its sha256 sum and not its name.
         Result is cached for performance, no invalidation planned as image
         churn is low on typical hosts.
+        If short is true, the repository is stripped from the result
         """
-        return self.image_name_resolver(co.get('Image', ''))
+        image = self.image_name_resolver(co.get('Image', ''))
+        if short:
+            return image.split('/')[-1]
+        return image
 
     def image_name_resolver(self, image):
         if image.startswith('sha256:') or '@sha256:' in image:


Test patch: