github.com/galamsiva2020/kubernetes-heapster-monitoring@v0.0.0-20210823134957-3c1baa7c1e70/common/elasticsearch/mapping.go (about)

     1  // Copyright 2015 Google Inc. All Rights Reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  package elasticsearch
    15  
    16  import (
    17  	"strings"
    18  
    19  	"k8s.io/heapster/metrics/core"
    20  )
    21  
    22  func MetricFamilyTimestamp(metricFamily core.MetricFamily) string {
    23  	return strings.Title(string(metricFamily)) + "MetricsTimestamp"
    24  }
    25  func metricFamilySchema(metricFamily core.MetricFamily) string {
    26  	metricSchemas := []string{}
    27  	for _, metric := range core.MetricFamilies[metricFamily] {
    28  		metricSchemas = append(metricSchemas,
    29  			`"`+metric.Name+`": {
    30    "properties": {
    31      "value": {
    32        "type": "double"
    33      }
    34    }
    35  }`,
    36  		)
    37  	}
    38  
    39  	return customMetricTypeSchema(string(metricFamily),
    40  		`"`+MetricFamilyTimestamp(metricFamily)+`": {
    41    "type": "date",
    42    "format": "strict_date_optional_time||epoch_millis"
    43  },
    44  "Metrics": {
    45    "properties": {
    46    `+strings.Join(metricSchemas, ",\r\n")+`
    47    }
    48  }
    49  `,
    50  	)
    51  }
    52  
    53  func customMetricTypeSchema(typeName string, customSchema string) string {
    54  	return `"` + typeName + `": {
    55    "properties": {
    56      "MetricsTags": {
    57        "properties": {
    58          "container_base_image": {
    59            "type": "string",
    60            "index": "analyzed",
    61            "fields": {
    62              "raw": {
    63                "type": "string",
    64                "index": "not_analyzed"
    65              }
    66            }
    67          },
    68          "container_name": {
    69            "type": "string",
    70            "index": "analyzed",
    71            "fields": {
    72              "raw": {
    73                "type": "string",
    74                "index": "not_analyzed"
    75              }
    76            }
    77          },
    78          "host_id": {
    79            "type": "string",
    80            "index": "not_analyzed"
    81          },
    82          "hostname": {
    83            "type": "string",
    84            "index": "analyzed",
    85            "fields": {
    86              "raw": {
    87                "type": "string",
    88                "index": "not_analyzed"
    89              }
    90            }
    91          },
    92          "labels": {
    93            "type": "string",
    94            "index": "analyzed",
    95            "fields": {
    96              "raw": {
    97                "type": "string",
    98                "index": "not_analyzed"
    99              }
   100            }
   101          },
   102          "namespace_id": {
   103            "type": "string",
   104            "index": "not_analyzed"
   105          },
   106          "namespace_name": {
   107            "type": "string",
   108            "fields": {
   109              "raw": {
   110                "type": "string",
   111                "index": "not_analyzed"
   112              }
   113            }
   114          },
   115          "nodename": {
   116            "type": "string",
   117            "index": "analyzed",
   118            "fields": {
   119              "raw": {
   120                "type": "string",
   121                "index": "not_analyzed"
   122              }
   123            }
   124          },
   125          "cluster_name": {
   126            "type": "string",
   127            "index": "not_analyzed"
   128          },
   129          "pod_id": {
   130            "type": "string",
   131            "index": "not_analyzed"
   132          },
   133          "pod_name": {
   134            "type": "string",
   135            "index": "analyzed",
   136            "fields": {
   137              "raw": {
   138                "type": "string",
   139                "index": "not_analyzed"
   140              }
   141            }
   142          },
   143          "resource_id": {
   144            "type": "string",
   145            "index": "not_analyzed"
   146          },
   147          "type": {
   148            "type": "string",
   149            "index": "not_analyzed"
   150          }
   151        }
   152      },
   153      ` + customSchema + `
   154    }
   155  }`
   156  }
   157  
   158  var mapping = `{
   159    "mappings": {
   160      "_default_": {
   161        "_all": {
   162          "enabled": false
   163        }
   164      },
   165      ` + metricFamilySchema(core.MetricFamilyCpu) + `,
   166      ` + metricFamilySchema(core.MetricFamilyFilesystem) + `,
   167      ` + metricFamilySchema(core.MetricFamilyMemory) + `,
   168      ` + metricFamilySchema(core.MetricFamilyNetwork) + `,
   169      ` + customMetricTypeSchema(core.MetricFamilyGeneral,
   170  	`"MetricsName": {
   171    "type": "string",
   172    "index": "analyzed",
   173    "fields": {
   174      "raw": {
   175        "type": "string",
   176        "index": "not_analyzed"
   177      }
   178    }
   179  },
   180  "GeneralMetricsTimestamp": {
   181  "type": "date",
   182  "format": "strict_date_optional_time||epoch_millis"
   183  },
   184  "MetricsValue": {
   185    "properties": {
   186      "value": {
   187        "type": "double"
   188      }
   189    }
   190  }`) + `,
   191  
   192      "events": {
   193        "properties": {
   194          "EventTags": {
   195            "properties": {
   196              "eventID": {
   197                "type": "string",
   198                "index": "not_analyzed"
   199              },
   200              "cluster_name": {
   201                "type": "string",
   202                "index": "not_analyzed"
   203              },
   204              "hostname": {
   205                "type": "string",
   206                "index": "analyzed",
   207                "fields": {
   208                  "raw": {
   209                    "type": "string",
   210                    "index": "not_analyzed"
   211                  }
   212                }
   213              },
   214              "pod_id": {
   215                "type": "string",
   216                "index": "not_analyzed"
   217              },
   218              "pod_name": {
   219                "type": "string",
   220                "index": "analyzed",
   221                "fields": {
   222                  "raw": {
   223                    "type": "string",
   224                    "index": "not_analyzed"
   225                  }
   226                }
   227              }
   228            }
   229          },
   230          "InvolvedObject": {
   231            "properties": {
   232              "apiVersion": {
   233                "type": "string",
   234                "index": "not_analyzed"
   235              },
   236              "fieldPath": {
   237                "type": "string",
   238                "fields": {
   239                  "raw": {
   240                    "type": "string",
   241                    "index": "not_analyzed"
   242                  }
   243                }
   244              },
   245              "kind": {
   246                "type": "string",
   247                "index": "not_analyzed"
   248              },
   249              "name": {
   250                "type": "string",
   251                "fields": {
   252                  "raw": {
   253                    "type": "string",
   254                    "index": "not_analyzed"
   255                  }
   256                }
   257              },
   258              "namespace": {
   259                "type": "string",
   260                "fields": {
   261                  "raw": {
   262                    "type": "string",
   263                    "index": "not_analyzed"
   264                  }
   265                }
   266              },
   267              "resourceVersion": {
   268                "type": "string",
   269                "index": "not_analyzed"
   270              },
   271              "uid": {
   272                "type": "string",
   273                "index": "not_analyzed"
   274              }
   275            }
   276          },
   277          "FirstOccurrenceTimestamp": {
   278            "type": "date",
   279            "format": "strict_date_optional_time||epoch_millis"
   280          },
   281          "LastOccurrenceTimestamp": {
   282            "type": "date",
   283            "format": "strict_date_optional_time||epoch_millis"
   284          },
   285          "Type": {
   286            "type": "string",
   287            "index": "not_analyzed"
   288          },
   289          "Message": {
   290            "type": "string",
   291            "fields": {
   292              "raw": {
   293                "type": "string",
   294                "index": "not_analyzed"
   295              }
   296            }
   297          },
   298          "Reason": {
   299            "type": "string",
   300            "index": "not_analyzed"
   301          },
   302          "Count": {
   303            "type": "long"
   304          },
   305          "Metadata": {
   306            "properties": {
   307              "creationTimestamp": {
   308                "type": "date",
   309                "format": "strict_date_optional_time||epoch_millis"
   310              },
   311              "name": {
   312                "type": "string",
   313                "fields": {
   314                  "raw": {
   315                    "type": "string",
   316                    "index": "not_analyzed"
   317                  }
   318                }
   319              },
   320              "namespace": {
   321                "type": "string",
   322                "fields": {
   323                  "raw": {
   324                    "type": "string",
   325                    "index": "not_analyzed"
   326                  }
   327                }
   328              },
   329              "resourceVersion": {
   330                "type": "string",
   331                "index": "not_analyzed"
   332              },
   333              "selfLink": {
   334                "type": "string",
   335                "index": "not_analyzed"
   336              },
   337              "uid": {
   338                "type": "string",
   339                "index": "not_analyzed"
   340              }
   341            }
   342          },
   343          "Source": {
   344            "properties": {
   345              "component": {
   346                "type": "string",
   347                "index": "not_analyzed"
   348              },
   349              "host": {
   350                "type": "string",
   351                "fields": {
   352                  "raw": {
   353                    "type": "string",
   354                    "index": "not_analyzed"
   355                  }
   356                }
   357              }
   358            }
   359          }
   360        }
   361      }
   362    }
   363  }`