Repository: kubeflow/pipelines

Issue:
Metadata Writer stopped getting the artifact types
All outputs are getting recorded as NoType.
```yaml
annotations:
    pipelines.kubeflow.org/component_spec: >-
      {"name": "Create visualizations", "outputs": [{"name": "Some Url 1",
      "type": "URI"}, {"name": "Some Url 2", "type": {"URI": {"data_type":
      "something"}}}, {"name": "Some HTML", "type": "HTML"}, {"name": "Some
      Markdown", "type": "Markdown"}, {"name": "Some metrics", "type":
      "Metrics"}]}
    pipelines.kubeflow.org/metadata_input_artifact_ids: '[]'
    pipelines.kubeflow.org/metadata_output_artifact_ids: >-
      [{"id": 32, "name": "some_html", "uri":
      "minio://mlpipeline/artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_html.tgz",
      "type": "NoType"}, {"id": 33, "name": "some_markdown", "uri":
      "minio://mlpipeline/artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_markdown.tgz",
      "type": "NoType"}, {"id": 34, "name": "some_metrics", "uri":
      "minio://mlpipeline/artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_metrics.tgz",
      "type": "NoType"}, {"id": 35, "name": "some_url_1", "uri":
      "minio://mlpipeline/artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_url_1.tgz",
      "type": "NoType"}, {"id": 36, "name": "some_url_2", "uri":
      "minio://mlpipeline/artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_url_2.tgz",
      "type": "NoType"}, {"id": 37, "name": "main-logs", "uri":
      "minio://mlpipeline/artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/main.log",
      "type": "NoType"}]
    sidecar.istio.io/inject: 'false'
    workflows.argoproj.io/node-name: create-visualizations-2-7sxmn.create-visualizations
    workflows.argoproj.io/outputs: >-
      {"artifacts":[{"name":"create-visualizations-some_html","path":"/tmp/outputs/Some_HTML/data","s3":{"endpoint":"minio-service.default:9000","bucket":"mlpipeline","insecure":true,"accessKeySecret":{"name":"mlpipeline-minio-artifact","key":"accesskey"},"secretKeySecret":{"name":"mlpipeline-minio-artifact","key":"secretkey"},"key":"artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_html.tgz"}},{"name":"create-visualizations-some_markdown","path":"/tmp/outputs/Some_Markdown/data","s3":{"endpoint":"minio-service.default:9000","bucket":"mlpipeline","insecure":true,"accessKeySecret":{"name":"mlpipeline-minio-artifact","key":"accesskey"},"secretKeySecret":{"name":"mlpipeline-minio-artifact","key":"secretkey"},"key":"artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_markdown.tgz"}},{"name":"create-visualizations-some_metrics","path":"/tmp/outputs/Some_metrics/data","s3":{"endpoint":"minio-service.default:9000","bucket":"mlpipeline","insecure":true,"accessKeySecret":{"name":"mlpipeline-minio-artifact","key":"accesskey"},"secretKeySecret":{"name":"mlpipeline-minio-artifact","key":"secretkey"},"key":"artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_metrics.tgz"}},{"name":"create-visualizations-some_url_1","path":"/tmp/outputs/Some_Url_1/data","s3":{"endpoint":"minio-service.default:9000","bucket":"mlpipeline","insecure":true,"accessKeySecret":{"name":"mlpipeline-minio-artifact","key":"accesskey"},"secretKeySecret":{"name":"mlpipeline-minio-artifact","key":"secretkey"},"key":"artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_url_1.tgz"}},{"name":"create-visualizations-some_url_2","path":"/tmp/outputs/Some_Url_2/data","s3":{"endpoint":"minio-service.default:9000","bucket":"mlpipeline","insecure":true,"accessKeySecret":{"name":"mlpipeline-minio-artifact","key":"accesskey"},"secretKeySecret":{"name":"mlpipeline-minio-artifact","key":"secretkey"},"key":"artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/create-visualizations-some_url_2.tgz"}},{"name":"main-logs","archiveLogs":true,"s3":{"endpoint":"minio-service.default:9000","bucket":"mlpipeline","insecure":true,"accessKeySecret":{"name":"mlpipeline-minio-artifact","key":"accesskey"},"secretKeySecret":{"name":"mlpipeline-minio-artifact","key":"secretkey"},"key":"artifacts/create-visualizations-2-7sxmn/create-visualizations-2-7sxmn-3549616354/main.log"}}]}

```


Discussion:
It's still recording types in some cases, but not in mall cases. There is some regression.
I've investigated the issue. It's caused by relaxation of Argo input/output name sanitization rules in the DSL compiler.

Resolving patch:
diff --git a/backend/metadata_writer/src/metadata_writer.py b/backend/metadata_writer/src/metadata_writer.py
--- a/backend/metadata_writer/src/metadata_writer.py
+++ b/backend/metadata_writer/src/metadata_writer.py
@@ -80,7 +80,9 @@ def patch_pod_metadata(
 
 def output_name_to_argo(name: str) -> str:
     import re
-    return re.sub('-+', '-', re.sub('[^-0-9a-z]+', '-', name.lower())).strip('-')
+    # This sanitization code should be kept in sync with the code in the DSL compiler.
+    # See https://github.com/kubeflow/pipelines/blob/39975e3cde7ba4dcea2bca835b92d0fe40b1ae3c/sdk/python/kfp/compiler/_k8s_helper.py#L33
+    return re.sub('-+', '-', re.sub('[^-_0-9A-Za-z]+', '-', name)).strip('-')
 
 def is_s3_endpoint(endpoint: str) -> bool:
     return re.search('^.*s3.*amazonaws.com.*$', endpoint)


Test patch: