Bug 2012039

Summary: After upgrading cluster to 4.8 the kube-state-metrics service doesn't export namespace labels anymore
Product: OpenShift Container Platform Reporter: Jayapriya Pai <janantha>
Component: MonitoringAssignee: Jayapriya Pai <janantha>
Status: CLOSED ERRATA QA Contact: Junqi Zhao <juzhao>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.8CC: amuller, anpicker, aos-bugs, erooth, juzhao, oarribas, pnair, spasquie
Target Milestone: ---   
Target Release: 4.8.z   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 2011698 Environment:
Last Closed: 2021-10-27 08:15:28 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 2012029    
Bug Blocks:    

Comment 2 Junqi Zhao 2021-10-18 09:27:06 UTC
tested with the PR, issue is fixed
for example, namespace ns1 has namespace labels
# oc get ns ns1 -o jsonpath="{.metadata.labels"}
{"deploy.method":"user","kubernetes.io/metadata.name":"ns1","network.openshift.io/policy-group":"ns1"}

seach with "kube_namespace_labels{namespace="ns1"}", we can see the namespace's labels 
# token=`oc sa get-token prometheus-k8s -n openshift-monitoring`
# oc -n openshift-monitoring exec -c prometheus prometheus-k8s-0 -- curl -k -H "Authorization: Bearer $token" 'https://prometheus-k8s.openshift-monitoring.svc:9091/api/v1/query?query=kube_namespace_labels%7Bnamespace%3D%22ns1%22%7D' | jq
{
  "status": "success",
  "data": {
    "resultType": "vector",
    "result": [
      {
        "metric": {
          "__name__": "kube_namespace_labels",
          "container": "kube-rbac-proxy-main",
          "endpoint": "https-main",
          "job": "kube-state-metrics",
          "label_deploy_method": "user",
          "label_kubernetes_io_metadata_name": "ns1",
          "label_network_openshift_io_policy_group": "ns1",
          "namespace": "ns1",
          "service": "kube-state-metrics"
        },
        "value": [
          1634549085.821,
          "1"
        ]
      }
    ]
  }
}

# oc -n openshift-monitoring get deploy kube-state-metrics -oyaml | grep metric-labels-allowlis
        - --metric-labels-allowlist=pods=[*],node=[*],namespaces=[*]

Comment 7 errata-xmlrpc 2021-10-27 08:15:28 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (OpenShift Container Platform 4.8.17 bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:3927